8.21.3 tabbing complex examples

Here is a simple example using the (rather confusing) \< command, along with \+ and \-:

\begin{tabbing}
\hspace{1in}\=\hspace{1in}\=\kill
\+ \> A   \\ % change left margin to second tab stop
\< left   \\ % but typeset "left" at first tab stop
\- B \> C \\ % return to normal left margin on next line
D \> E    \\
\end{tabbing}

The output looks like this (except not in typewriter):

      A
left 
      B   C
D     E

This last example typesets a Pascal function (in typewriter), defining new tab stops and using \+ and \- for the different indentation levels:

{\tt \frenchspacing \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 (not typewriter) code, there are quite a few packages, including algorithm2e, fancyvrb, listings, and minted.


Unofficial LaTeX2e reference manual