About these ads

# Formatting code in LaTex (tabbing, verbatim)

Formatting code in LaTex is as astonishingly easy, once one knows how to do it.

There is a command “tabbing”, which is used in the same way as for example “centering”, except that one has to tell the computer where to set a tab.

\begin{tabbing} if \= (condition) \{ \\ % inserts a tab just after the "if"-command. \> then statement \=\\ % go to the defined tab and set a new one \}\\ else \{ \\ \> else statement     \> next tab is here\\ \}\\ \end{tabbing}

Copy-paste the code into your LaTex-file and see yourself.

One can use as many \> in a sequence as needed, as long as enough tabs have been defined before.

E.g.

\begin{tabbing} o \= o \= o\\ o \> \> o\\ o \> o \> o\\ \end{tabbing}

Another way to just format your code if you already have it in a “tabbed” version is to use “verbatim”.

\begin{verbatim} Your code goes here. \end{verbatim}

About these ads