## Wednesday, November 24, 2010

### LaTeX Spaces and Boxes

Courtesy of: http://www.personal.ceu.hu/tex/spacebox.htm

Commands manipulating horizontal and vertical spaces, and holding material in boxes:

\vspace{length}, \vspace*{length}

leave out given vertical space

\smallskip, \medskip, \bigskip

leave out certain spaces

\addvspace{length}

extend the vertical space until it reaches length.

\vfill

stretch vertical space so that it fills all empty space

\hspace{length}, \hpace*{length}

leave out given horizontal space

\hfill, \hrulefill, \dotfill

fill out all available horizontal space with a line or with dots

\rule{width}{thickness}

draw a line

\makebox{text}, \mbox{text}

enclose text into a box and then print, can be used in math mode.

\framebox{text}, \fbox{text}

enclose text into a framed box and then print.

\parbox{width}{text}

insert several paragraphs into a box of given width

\raisebox{dist}{text}

raise or lower (if dist is negative) the box created from text.

\newsavebox{boxname}

define the holder boxname to store a box.

\savebox{boxname}{text}, \sbox{boxname}{text}

save text int the holder boxname

\usebox{boxname}

use material stored in box holder boxname

More in detail:

\vspace

\vspace[*]{length}

The \vspace command adds vertical space. The length of the space can be expressed in any terms that LaTeX understands, i.e., points, inches, etc. You can add negative as well as positive space with an \vspace command.

LaTeX removes vertical space that comes at the end of a page. If you don't want LaTeX to remove this space, include the optional * argument. Then the space is never removed.

\smallskip, \medskip, \bigskip

The \smallskip command is equivalent to \vspace{smallskipamount} where smallskipamount is determined by the document style.

The \medskip command is equivalent to \vspace{medskipamount} where medskipamount is determined by the document style.

The \bigskip command is equivalent to \vspace{bigskipamount} where bigskipamount is determined by the document style.

\addvspace{length}

The \addvspace command normally adds a vertical space of height length. However, if vertical space has already been added to the same point in the output by a previous \addvspace command, then this command will not add more space than needed to make the natural length of the total vertical space equal to length.

\vfill

The \vfill fill command produces a rubber length which can stretch or shrink vertically..

\hspace

\hspace[*]{length}

The \hspace command adds horizontal space. The length of the space can be expressed in any terms that LaTeX understands, i.e., points, inches, etc. You can add negative as well as positive space with an \hspace command. Adding negative space is like backspacing.
LaTeX removes horizontal space that comes at the end of a line. If you don't want LaTeX to remove this space, include the optional * argument. Then the space is never removed.

\hfill, \hrulefill, \dotfill

The \hfill fill command produces a rubber length which can stretch or shrink horizontally. It will be filled with spaces.

The \hrulefill fill command produces a rubber length which can stretch or shrink horizontally. It will be filled with a horizontal rule.

The \dotfill command produces a rubber length that produces dots instead of just spaces.

\rule

\rule[raise-height]{width}{thickness}

The \rule command is used to produce horizontal lines. The arguments are defined as follows.

raise-height: specifies how high to raise the rule (optional)
width: specifies the length of the rule (mandatory)
thickness: specifies the thickness of the rule (mandatory)

\makebox, \mbox

\makebox[width][position]{text}
\mbox {text}

The \makebox command creates a box to contain the text specified. The width of the box is specified by the optional width argument. The position of the text within the box is determined by the optional position argument.
c - centered (default)
l - flushleft
r - flushright

The \mbox command creates a box just wide enough to hold the text created by its argument.

\framebox, \fbox

\framebox[width][position]{text}
\fbox{text}

The \framebox command is exactly the same as the \makebox command, except that it puts a frame around the outside of the box that it creates.
The framebox command produces a rule of thickness \fboxrule, and leaves a space \fboxsep between the rule and the contents of the box.

The \fbox command is exactly the same as the \mbox command, except that it puts a frame around the outside of the box that it creates.

\parbox

\parbox[position]{width}{text}

A parbox is a box whose contents are created in paragraph mode. The \parbox has two mandatory arguments:
width: specifies the width of the parbox; and
text: the text that goes inside the parbox.

LaTeX will position a parbox so its center lines up with the center of the text line. An optional first argument, position, allows you to line up either the top or bottom line in the parbox.

A \parbox command is used for a parbox containing a small piece of text, with nothing fancy inside. In particular, you shouldn't use any of the paragraph-making environments inside a \parbox argument. For larger pieces of text, including ones containing a paragraph-making environment, you should use a minipage environment.

\raisebox

\raisebox{distance}[extend-above][extend-below]{text}

The \raisebox command is used to raise or lower text. The first mandatory argument specifies how high the text is to be raised (or lowered if it is a negative amount). The text itself is processed in LR mode.

Sometimes it's useful to make LaTeX think something has a different size than it really does - or a different size than LaTeX would normally think it has. The \raisebox command lets you tell LaTeX how tall it is.

The first optional argument, extend-above, makes LaTeX think that the text extends above the line by the amount specified. The second optional argument, extend-below, makes LaTeX think that the text extends below the line by the amount specified.

\newsavebox

\newsavebox{cmd}

Declares cmd, which must be a command name starting with a \, that is not already defined, to be a bin for saving boxes.

\savebox, \sbox

\savebox{cmd}[width][pos]{text}, \sbox{cmd}[text]

These commands typeset text in a box just as for \mbox or \makebox. However, instead of printing the resulting box, they save it in bin cmd, which must have been declared with \newsavebox.

\usebox

\usebox{cmd}

Prints the box most recently saved in bin cmd by a \savebox command.