Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have to write a table with two columns and in each column I have to place small C code snippets. Using the \code{} in each column seems to be very tedious because I have to write \code{} in each line on each box of the table.

\caption{Possible transformations}
code1           & code2 \\\hline
\code{float PI = 3.14;} & \code{constexpr double PI = 3.14;} \\\hline
\code{if(A > B) A = B } & \code{void F(T\& A, const T\& B)}\\
                & \code{\{if (A>B) A=B; \} } \\\hline

Also I want 2-3 lines of code in each box. How do I do that? Thanks.

share|improve this question
Please add a complete minimal working example (MWE) that illustrates your problem. – Kurt Sep 3 '12 at 19:48
Note that an MWE should include document class, all necessary packages and definitions (where does \code come from, for example?) and a document environment. In other words, we should be able to copy the whole thing into a new file and compile it. At the same time, it should be minimal, so any packages etc. that doesn't influence the problem, should be left out. – Torbjørn T. Sep 3 '12 at 20:08

1 Answer 1

up vote 3 down vote accepted

You could use the tabu and the fancyvrb packages:



Some lines
of a long
verbatim fragment
Some lines
of another long
verbatim fragment


enter image description here

Of course, if your verbatim material doesn't require any special treatment and doesn't include any special characters, you can use the >{...} syntax to add \ttfamily to the columns and simply say something like this:




code1 & code2 \\
float PI = 3.14; & constexpr double PI = 3.14; \\
if(A > B) A = B  & void F(T\& A, const T\& B) \\
& \{if (A>B) A=B; \} \\


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.