Documentation For Fancybox - Sty: Box Tips and Tricks For L TEX
Documentation For Fancybox - Sty: Box Tips and Tricks For L TEX
sty:
Box tips and tricks for LATEX
Timothy Van Zandt
[email protected]
Version 1.3
September 19, 2000
Contents
1
Fancy frames
Math
Floats
10
Lists
12
Superimposing boxes
13
15
10
17
11
Verbatim
18
12
Changes
27
Fancy frames
The distance between the box and the frame is \fboxsep, as with LATEXs
\fbox command. The commands use other parameters as well:
\shadowbox The width of the frame is \fboxrule (the same as with \fbox).
The width of the shadow is \shadowsize (default: 4pt).
\doublebox The width of the inner frame is .75\fboxrule, and the width of
the outer frame is 1.5\fboxrule. The distance between the two frames
is 1.5\fboxrule plus .5pt.
1
6pt.
In this documentation, the default value of \fboxsep has been changed from 3pt to
\ovalbox The width of the frame is set by the \thinlines declaration. The
diameter of the corner arcs is set with the \cornersize command.
\cornersize{num}
sets the diameter of the corners arcs to num times the lessor of the
width and height of the box.
\cornersize*{dim}
sets the diameter of the corner arcs to dim. This is all approximate,
because LATEX has a limited range of arc sizes to choose from. The
default is
\cornersize{.5}
\Ovalbox This is like \ovalbox, except that the width of the lines is set by
the \thicklines declaration.
There are no analogs to LATEXs \framebox command, which has various
optional arguments not supported by \fbox. You can get the exact same
functionality by putting the argument of the above framing commands in a
\makebox.
There is also a variant \fancyoval of LATEXs \oval picture object. The
difference is that \oval always makes the diameter of the corner arcs as
large as possible, and \fancyoval uses the \cornersize command to set
the diameter.
with LATEX. I will use \fbox for the leading example of a box framing command,2 and \rotateleft for the leading example of a box rotation command. (fancybox.sty does not contain a \rotateleft command, as this
must be implemented via \specials, but there are numerous box-rotation
style files around.) However, most of what is said here applies to any LR-box
command.
In each LR-box command, the text is processed in restricted horizontal mode,
which is referred to as LR-mode in Lamports LATEX: Users Guide and
Reference Manual. In restricted horizontal mode, the input, consisting of
regular characters and boxes, is made into one (long or short) line. There is
no line-breaking, nor can there be vertical mode material such as an entire
displayed equation. However, the fact that you can include another box
means that this isnt really a restriction.
For one thing, alignment environments such as LATEXs tabular are just
boxes, and thus present no problem. Picture environments and the LR-box
commands themselves are also just boxes. Entire paragraphs or other vertical
mode material such as displayed equations can be nested in a \parbox or
minipage.
In the examples using \fbox, be aware that the default value of \fboxsep has been
changed in this documentation from 3pt to 6pt.
and
\newsavebox{\mybox}
\sbox{\mybox}{blah}
\usebox{\mybox}
is that Sbox saves the contents globally, and \TheSbox erases the contents globally.
Math
In-line math, or pieces of a displayed equation (as opposed to a whole equation), are horizontal mode material, but most LR-box commands switch out
of math mode when they occur in math mode. Thus, you have to explicitly
switch back in to math mode when desired.4 For example:
$x + y = \fbox{$\Omega$}$
x+y =
You also have to explicitly write
\scriptstyle, \scriptscriptstyle or \displaystyle
if you want one of these special math styles. For example, here I will frame
an equation, but not the equation number:
\begin{equation}
\fbox{$\displaystyle
\int_{\Omega_0} \zeta(\omega) d\omega
\geq \bar{r}$}
\end{equation}
()d r
(1)
Entire displayed equations or eqnarray environments work differently because they are vertical mode material. Thus, they have to go inside a \parbox
or minipage. E.g.,
\newlength{\mylength}
\[
\setlength{\fboxsep}{15pt}
\setlength{\mylength}{\linewidth}
\addtolength{\mylength}{-2\fboxsep}
4
\addtolength{\mylength}{-2\fboxrule}
\fbox{%
\parbox{\mylength}{
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\begin{equation}
x + y = z
\end{equation}}}
\]
x+y =z
(2)
The outer \[ \] are just used to display the boxed equation, rather than
actually switch into math mode. Note how I set the width of the \parbox
so that the displayed box would exactly have width \linewidth.5
I also set the display skips to 0pt and increased the size of \fboxsep so that
I would have the same distance all around between the equation and the
frame.
This is again a mouthful, and so I might instead define:6
\newenvironment{FramedEqn}%
{\setlength{\fboxsep}{15pt}
\setlength{\mylength}{\linewidth}%
\addtolength{\mylength}{-2\fboxsep}%
\addtolength{\mylength}{-2\fboxrule}%
\Sbox
\minipage{\mylength}%
\setlength{\abovedisplayskip}{0pt}%
\setlength{\belowdisplayskip}{0pt}%
\equation}%
{\endequation\endminipage\endSbox
\[\fbox{\TheSbox}\]}
5
That is what \mylength is for. It is better to define a single scratch length that you
reuse rather than creating a new one each time.
6
The reason for using \minipage instead of \begin{minipage}, and so on, is that
with AmS-LATEX, \begin and \end cannot appear in the definition of a new equation
environment.
P (P )
1
3
(3)
f (x)dx =
xi
iF
Floats
A common mistake is to put a whole table, figure or other float environment inside an LR-box command. Instead, you should put everything that is
inside the environment (including the \caption, if you want that boxed too)
inside a minipage of the desired width, and then put the minipage inside
the LR-box command.
For example:
\begin{table}[h]
\begin{center}
\fbox{%
\begin{minipage}{.8\textwidth}
\begin{center}
\begin{tabular}{rl}
foo & bar
\end{tabular}
\end{center}
\caption{A table of foo and bar.}
\end{minipage}}
\end{center}
\end{table}
foo
bar
Note how I had to use center twice: once to center the framed box, and
again to center the stuff inside the box.
That is a mouthful, and so I might define a FramedTable environment like
the following, which sets the size of the minipage so that the framed box is
exactly the width of the page (no need for the first center environment this
time):
\newenvironment{FramedTable}%
{\begin{table}[h]
\begin{Sbox}%
\setlength{\mylength}{\textwidth}%
\addtolength{\mylength}{-2\fboxsep}%
\addtolength{\mylength}{-2\fboxrule}%
\begin{minipage}{\mylength}}%
{\end{minipage}\end{Sbox}\fbox{\TheSbox}\end{table}}%
foo
bar
10
If you dont add a caption to a float, it doesnt matter much what floating
environment you use (e.g., table, figure or whatever). Thus, you can put
anything in a landscape float. For example, suppose I have a very wide
equation. Then I can write:
\begin{landfloat}{table}{\rotateleft}
\begin{equation}
...
\end{equation}
\end{landfloat}
fancybox.sty defines a generic caption, \GenericCaption, that doesnt affect the numbering of floats, doesnt make an entry in a list of floats, and
doesnt add anything to the argument you give. I could have used this if I
wanted to add a caption to the previous example.
List and other such environments work best inside a minipage environment rather
than a \parbox.
11
\setlength{\fboxsep}{10pt}%
\fbox{%
\begin{Bcenter}
Love of life\\
and other short stories\\
by Policarpa Salabarrieta
\end{Bcenter}}
Love of life
and other short stories
by Policarpa Salabarrieta
12
Galanga root
Coconut
My list: Tempeh
Lists
13
\fbox{%
\begin{Bdescription}
\item[David] Groceries
\item[Eli] Hamster cages\\
Surreal numbers
\item(3pt)[Doris] Pick up Peter
\end{Bdescription}}
David Groceries
Eli
Hamster cages
Surreal numbers
Superimposing boxes
The command
14
Censored!
You will only notice the difference between \boxput and \boxput* if you are using
color implemented by \specials
15
\newcommand{\titledframe}[2]{%
\boxput*(0,1){\psframebox*{#1}}%
{\psframebox[framesep=12pt]{#2}}}
The following example illustrated roughly how it works, but My title does
not blot out the frame behind it because this documentation does not use
PSTricks.
\titledframe{My title}{%
\parbox{2in}{The title is superimposed
on the top part of the frame.}}
My title
The title is superimposed on
the top part of the frame.
The commands
\fancyput*(x ,y){LR stuff }
\thisfancyput*(x ,y){LR stuff }
are pretty much like \put commands in a LATEX picture environment whose
origin is 1 inch down and to the right from the top left corner of the page.9
The only differences are that (i) that any LR-mode material is permitted
(including LATEX picture environment, of course), (ii) the coordinate is optional (0pt,0pt) is substituted by default), and (iii) if the coordinate is
included, you must specify the units.
\thisfancyput affects only the current page, and is a global declaration
(analogous to \thispagestyle).
If you include the optional *, then the command adds to, rather than replaces,
other things that have been inserted with \fancyput or \thisfancyput.
These commands are particularly useful for framing a page, because you can
get a frame that is, e.g., 1 inch from each side of the physical page without
having to worry about what margins you are using for the document. Here
is an example:
9
'
16
\thisfancyput(3.25in,-4.5in){%
\setlength{\unitlength}{1in}\fancyoval(7,9.5)}
You could also use \fancyput to add some kind of watermark or background image (e.g., a light gray DRAFT).
There are other commands that directly frame or in some other way box the
page of text:
\fancypage{cmds1 }{cmds2 }
\thisfancypage{cmds1 }{cmds2 }
Each finished page, before adding the headers and footers, (and thus having
width and height \textwidth and \textheight, is boxed with
cmds1 {pagebox }
Thus, cmds1 should be, or should end with, a command whose argument
can be a box, such as \fbox or \rotateleft.
Then the headers and footers are added, using the new width of the page,
and this is boxed with
cmds2 {pagebox }
The same rules apply to cmds2 as to cmds1 .
Here is an example:
\thisfancypage{%
\setlength{\fboxsep}{8pt}%
\setlength{\shadowsize}{8pt}%
\shadowbox}{}
Warning: The commands described in this section change LATEXs output
routine, and may not work with document styles that do the same. Also,
bad arguments can cause serious errors with uninformative error messages.
&
10
17
18
\Landscape*{11in}{8.5in}{\rotateright}
These environments switch the text width and height, leaving the margins
exactly as they were before. It is quite possible that you want to make
other changes to the page parameters after switching to landscape mode, but
as Lamport points out the LATEX Users Guide and Reference Manual, this
generally doesnt work right in the middle of the document. fancybox.sty
has a command \UsePageParameters which gets around this. It should be
used right after you change the page parameters (and the page parameter
changes should come right after the beginning of the landscape environment,
or \clearpage).
Warning: The commands and environments described in this section change
LATEXs output routine, and may not work with document styles that do the
same. Also, bad arguments can cause serious errors with uninformative error
messages.
11
Verbatim
19
if { foo } { bar } fi
\end{verbatim}
\end{minipage}
\end{Sbox}
\setlength{\fboxsep}{8pt}
\fbox{\TheSbox}
\My \Program \Listing
if { foo } { bar } fi
fancybox.sty also contains a command that fixes LATEXs LR-box commands for use with verbatim text:
\VerbBox{cmd }{LR stuff }
This is like
cmd {LR stuff }
but LR stuff can contain verbatim text.10 For example:
\VerbBox{\fbox}{\verb+\foo{bar}+}
\foo{bar}
For footnotes, put the command \VerbatimFootnotes in the preamble, and
then you can use verbatim commands or environments in the argument of
\footnote. This is an optional feature because it might conflict with somebody elses modification of the footnote system.
If you try to define your own framed verbatim environment with
\newenvironment{FramedVerb}%
{\begin{Sbox}\begin{minipage}{5in}\begin{verbatim}}
{\end{verbatim}\end{minipage}\end{Sbox}
\setlength{\fboxsep}{8pt}\fbox{\TheSbox}}
10
Or other tricks that involve \catcode changes, as occurs with some foreign language
macros.
20
If you need to allow something to come before \end{Verbatim}, then you have two
options:
Put the command \AltGetVerbatim in the preamble. This switches to a scheme
21
22
Be careful that your word processing does not insert one for you.
23
\UseVerb{cmd } Like \UseVerbatim, but without any particular formatting. It is intended for including short pieces of literal text saved with
\SaveVerb (below).13
\SaveVerb[whatever ]{cmd }char literal char
This is like \Verb, but it saves literal as cmd , and then returns to the
optional argument whatever . Like the SaveVerbatim environment, it
defines cmd globally without checking whether cmd is already defined.
Without the optional argument, the most common use is for including
verbatim text in a \marginpar, \section or other command argument.
The optional argument can be used for special tricks. For example,
all the listings of commands in this documentation use \vitem in a
description environment, where \vitem is defined by:14
\newcommand{\vitem}%
{\SaveVerb[{\item[\UseVerb{\MyTemp}]}]{\MyTemp}}
Whereas
\item[\Verb"\foo"]
would not work because after \item reads its argument it is too late
to interpret \foo literally,
\vitem"foo"
does work because it is equivalent to
\SaveVerb{\MyTemp}"foo"\item[\UseVerb{\MyTemp}]
These environments and commands use various parameters that make it easy
to customize their behavior. However, until you want to find the need for
such customization, you might as well ignore the rest of this section.
Internally, fancybox.sty separates the reading and formatting of verbatim
text. Most of the environments and commands perform both functions, but
SaveVerbatim and \SaveVerb only read the text, while UseVerbatim (and
company) and \UseVerb only format the text. VerbatimOut gets special
treatment. The parameters that apply to each class of verbatim environment
or command is listed in Table 3.
13
But it can also be used for multiple lines saved with the SaveVerbatim environment
if you want to do the formatting yourself. E.g., try this in a tabbing environment with
\VerbatimTab appropriately defined.
14
The braces enclosing the optional argument of \SaveVerb prevent the ] inside the
argument from being mistaken for the end of the argument.
24
Where
What
Environments
that format
\VerbatimSpace
\VerbatimTab
\VerbatimFont
\VerbatimFuzz
\EveryVerbatimLine
\EveryVerbatim
\ThisVerb
Environments
that read
\EveryVerbatimCodes
\ThisVerbCodes
\Verb and
\UseVerb
\VerbSpace
\VerbTab
\VerbFont
\EveryVerb
\ThisVerb
\Verb and
\SaveVerb
\EveryVerbCodes
\ThisVerbCodes
VerbatimOut
\EveryVerbOutCodes
\ThisVerbCodes
\EveryVerbOutLine
\ThisVerb
25
1
2
26
\setlength{\fboxsep}{15pt}
\setlength{\mylength}{\linewidth}
\EveryVerbatim Whatever else you want to say before formatting the verbatim text. By default, it does nothing.
\ThisVerb This is executed before any of the commands above, and then
its value is cleared. Use this to customize a single verbatim formatting
environment.
Here is a description of the parameters for environments that read the verbatim text:
\EveryVerbatimCodes This command is inserted just before reading the
verbatim text. Use it to play with \catcodes (see the TEXbook). For
example, I might type
\renewcommand{\EveryVerbatimCodes}{\catcode\"=14}
if I want to use " as a comment character in verbatim text.15
\ThisVerbCodes This command is executed before \EveryVerbCodes, and
then it is cleared. Use this to fool with the \catcodes of a single
verbatim environment.
The parameters for \Verb, \UseVerb and \SaveVerb and the VerbatimOut
environment are analogous to the similar commands for other environments.
Here is an example of the use of \ThisVerb to define a variant of \Verb that
uses to mark spaces:
\newcommand{\SVerb}{%
\renewcommand{\ThisVerb}%
{\renewcommand{\VerbatimSpace}{\ttspace}}%
\Verb}
15
Here is another \catcode trick. We make " a short verbatim command, so that we
can say "foo" instead of \Verb"foo":
\def\MyQuote{"}
% \MyQuote is now the character ",
\def\temp{\Verb"} %
in case I need it.
\catcode\"=13
% Now " is like a command.
\let"\temp
% Now "foo" is like \Verb"foo"
\def\do{\noexpand\do\noexpand}
% Now " can be used in verbatim
\edef\dospecials{\dospecials\do\"} % environments anyway.
27
Finally, without further comment, here are the definitions of the example and
example* environments that were used for the examples in this document:
% 1. Save example verbatim to \jobname.tmp,
% 2. Input verbatim with \catcode\"=14 (" is a comment).
% 3. Input again with \catcode\"=9 (" is ignored).
\renewcommand{\EveryVerbatimLine}[2]{}
\renewcommand{\EveryVerbOutLine}[2]{}
\newcommand{\BeginExample}{%
\VerbatimEnvironment\begin{VerbatimOut}{\jobname.tmp}}
\newcommand{\EndExample}{%
\end{VerbatimOut}%.
\renewcommand{\EveryVerbatimLine}{}%
\renewcommand{\EveryVerbatimCodes}{\catcode\"=14}%
\LVerbatimInput{\jobname.tmp}%
\catcode\"=9}
\newenvironment{example}{\BeginExample}{\EndExample
\begin{center}\input{\jobname.tmp}\end{center}}
\newenvironment{example*}{\BeginExample}%
{\EndExample \input{\jobname.tmp}}
\newenvironment{example**}{\BeginExample}%
{\EndExample \globaldefs=1 \input{\jobname.tmp}}
12
Changes
28
29