[texhax] Selecting which edge should be framed in a box

Martin Heller mr_heller at yahoo.dk
Sun May 2 20:46:23 CEST 2010


On 2010-05-02 18:41, José Romildo Malaquias wrote:

> - a command to put frames in all edges but the last one
> - a command to put frames in all edges but the first one
> - a command to put frames in the vertical edges (that is, left and
>    right)

\documentclass{article}
\usepackage{pgfkeys}

\makeatletter
\newif\iffleft
\newif\iffright
\newif\ifftop
\newif\iffbottom
\pgfkeys{
   /myfbox/.cd,
   left/.is if     = fleft,
   right/.is if    = fright,
   top/.is if      = ftop,
   bottom/.is if   = fbottom,
   left/.default   = true,
   right/.default  = true,
   top/.default    = true,
   bottom/.default = true
}
\pgfqkeys{/myfbox}{%
   left=true,
   right=true,
   top=true,
   bottom=true,
}
\newcommand\myfbox[2][]{%
   \begingroup
   \pgfqkeys{/myfbox}{#1}%
   \let\@frameb at x\@my at frameb@x
   \fbox{#2}%
   \endgroup
}%
\def\@my at frameb@x#1{%
   \@tempdima\fboxrule
   \advance\@tempdima\fboxsep
   \advance\@tempdima\dp\@tempboxa
   \hbox{%
     \lower\@tempdima\hbox{%
       \vbox{%
	\ifftop\hrule\@height\fboxrule\fi
	\hbox{%
	  \iffleft\vrule\@width\fboxrule\fi
           #1%
           \vbox{%
             \vskip\fboxsep
             \box\@tempboxa
             \vskip\fboxsep}%
           #1%
           \iffright\vrule\@width\fboxrule\fi
	}%
         \iffbottom\hrule\@height\fboxrule\fi
       }%
     }%
   }%
}%
\makeatother

\begin{document}

\myfbox[top=false]{Foo}
\myfbox[bottom=false]{Foo}
\myfbox[bottom=false,top=false]{Foo}
\myfbox{Foo}
\fbox{Foo}

\end{document}



More information about the texhax mailing list