[Tex/LaTex] Width of tab character

formattingverbatim

I'm using the verbatim environment to format some code.

Is there a way to set the desired number of spaces represented by a tab character?

What is the default number of spaces?

Best Answer

If you don't need any further formatting of the verbatim stuff you can use the package moreverb or fancyvrb. The provided environment verbatimtab by moreverb has an optional argument to specify the width of a tab. The package fancyvrb provides the option tabsize to speficy the width.

\documentclass{article}
\usepackage{verbatim,moreverb,fancyvrb}
\begin{document}

package \texttt{verbatim}
\begin{verbatim*}
Hello World!
Hello   World!
\end{verbatim*}

package \texttt{moreverb}
\begin{verbatimtab}
Hello World!
Hello   World!
\end{verbatimtab}

package \texttt{fancyvrb}
\begin{Verbatim}
Hello World!
Hello   World!
\end{Verbatim}
\end{document}  

enter image description here

N.b. to set the tab size in the verbatimtab environment, do the following:

\begin{verbatimtab}[tabsize]

Where tabsize is the number of spaces that the tab should represent.

Related Question