Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verbatim environment inside LaTeX cell?

Tags:

I would like to insert some XML inside a LaTeX table, so I thought that \begin{verbatim}.. will be a good solution for preserving the syntax, but it does not work like this:

\begin{tabular}{ ll }
   sample & 
   \begin{verbatim}
      <how>
          <to value="make" />
          <this value="work" />
      </how>
   \end{verbatim}
\end{tabular}

How can I make this work?

like image 931
jwaliszko Avatar asked Jul 10 '10 17:07

jwaliszko


People also ask

How do you write verbatim in LaTeX?

You can do this with the verbatim environment. That is, if you put the command \begin{verbatim} at the beginning of some text and \end{verbatim} at the end, then LATEX will reproduce the text in the output, in typewriter style, exactly as it is typed in the input.

What is verbatim environment in LaTeX?

The verbatim environment is a paragraph-making environment that gets LaTeX to print exactly what you type in. It turns LaTeX into a typewriter with carriage returns and blanks having the same effect that they would on a typewriter.


1 Answers

You need to put it inside a minipage, like so:

\begin{tabular}{ ll }
sample &
\begin{minipage}{3in}
\begin{verbatim}
<how>
   <to value="make" />
   <this value="work" />
</how>
\end{verbatim}
\end{minipage}
\end{tabular}

Unfortunately, this means you have to decide how wide the column will be in advance (that's what the {3in} part does). I usually start with 3in and then adjust it up or down until the page looks good and I stop getting overfull hbox messages.

like image 78
zwol Avatar answered Oct 16 '22 14:10

zwol