tabbing

Synopsis:

\begin{tabbing}
row1col1 \= row1col2 ...  \\
row2col1 \> row2col2 ...  \\
...
\end{tabbing}

Align text in columns, by setting tab stops and tabbing to them much as was done on a typewriter. This is less often used than the environments tabular (see tabular) or array (see array) because in those the width of each column need not be constant and need not be known in advance.

This example has a first line where the tab stops are set to explicit widths, ended by a \kill command (which is described below):

\begin{tabbing}
\hspace{1.2in}\=\hspace{1in}\=\kill
Ship                \>Guns             \>Year    \\ 
\textit{Sophie}     \>14               \>1800    \\
\textit{Polychrest} \>24               \>1803    \\
\textit{Lively}     \>38               \>1804    \\
\textit{Surprise}   \>28               \>1805    \\
\end{tabbing}

Both the tabbing environment and the more widely-used tabular environment put text in columns. The most important distinction is that in tabular the width of columns is determined automatically by LaTeX, while in tabbing the user sets the tab stops. Another distinction is that tabular generates a box, but tabbing can be broken across pages. Finally, while tabular can be used in any mode, tabbing can be used only in paragraph mode and it always starts a new paragraph, without indentation.

Moreover, as shown in the example above, there is no need to use the starred form of the \hspace command at the beginning of a tabbed row. The right margin of the tabbing environment is the end of line, so that the width of the environment is \linewidth.

The tabbing environment contains a sequence of tabbed rows. The first tabbed row begins immediately after \begin{tabbing} and each row ends with \\ or \kill. The last row may omit the \\ and end with just \end{tabbing}.

At any point the tabbing environment has a current tab stop pattern, a sequence of n > 0 tab stops, numbered 0, 1, etc. These create n corresponding columns. Tab stop 0 is always the left margin, defined by the enclosing environment. Tab stop number i is set if it is assigned a horizontal position on the page. Tab stop number i can only be set if all the stops 0, …, i-1 have already been set; normally later stops are to the right of earlier ones.

By default any text typeset in a tabbing environment is typeset ragged right and left-aligned on the current tab stop. Typesetting is done in LR mode (see Modes).

The following commands can be used inside a tabbing environment. They are all fragile (see \protect).

\\ (tabbing)

End a tabbed line and typeset it.

\= (tabbing)

Sets a tab stop at the current position.

\> (tabbing)

Advances to the next tab stop.

\<

Put following text to the left of the local margin (without changing the margin). Can only be used at the start of the line.

\+

Moves the left margin of the next and all the following commands one tab stop to the right, beginning tabbed line if necessary.

\-

Moves the left margin of the next and all the following commands one tab stop to the left, beginning tabbed line if necessary.

\' (tabbing)

Moves everything that you have typed so far in the current column, i.e., everything from the most recent \>, \<, \', \\, or \kill command, to the previous column and aligned to the right, flush against the current column’s tab stop.

\` (tabbing)

Allows you to put text flush right against any tab stop, including tab stop 0. However, it can’t move text to the right of the last column because there’s no tab stop there. The \` command moves all the text that follows it, up to the \\ or \end{tabbing} command that ends the line, to the right margin of the tabbing environment. There must be no \> or \' command between the \` and the \\ or \end{tabbing} command that ends the line.

\a (tabbing)

In a tabbing environment, the commands \=, \' and \` do not produce accents as usual (see Accents). Instead, use the commands \a=, \a' and \a`.

\kill

Sets tab stops without producing text. Works just like \\ except that it throws away the current line instead of producing output for it. Any \=, \+ or \- commands in that line remain in effect.

\poptabs

Restores the tab stop positions saved by the last \pushtabs.

\pushtabs

Saves all current tab stop positions. Useful for temporarily changing tab stop positions in the middle of a tabbing environment.

\tabbingsep

Distance of the text moved by \' to left of current tab stop.

This example typesets a Pascal function:

\begin{tabbing}
function \= fact(n : integer) : integer;\\
         \> begin \= \+ \\
               \> if \= n > 1 then \+ \\
                        fact := n * fact(n-1) \- \\
                  else \+ \\
                        fact := 1; \-\- \\
            end;\\
\end{tabbing}

The output looks like this.

function fact(n : integer) : integer;
         begin
               if n > 1 then
                  fact := n * fact(n-1);
               else
                  fact := 1;
         end;

This example is just for illustration of the environment. To actually typeset computer code in typewriter like this, a verbatim environment (see verbatim) would normally be best. For pretty-printed code, there are quite a few packages, including algorithm2e, fancyvrb, listings, and minted.

© 2007–2018 Karl Berry
Public Domain Software
http://latexref.xyz/tabbing.html