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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need help aligning text that spans multiple lines where I have Verbatim code in between. Here is a mock example to show what I mean:

Fruit        Amount
Apple        $3.00

... some code here.

Orange       $4.00
Peach        $7.55

... more code.

Grapes       $11.50

So basically I need the Fruit and Amount columns to always align as shown, even through the verbatim code. My question is, how can this be done with the least amount of pain? :)

share|improve this question

migrated from stackoverflow.com Feb 9 '11 at 4:06

This question came from our site for professional and enthusiast programmers.

Try to avoid using the words latex and harder in the same sentence. Some of us are still infantile at heart and our minds are likely to stray :-) – paxdiablo Feb 9 '11 at 2:58
@Chris R use a monospace font for verbatim text and make sure you have an editor that supports tabbing. – Yiannis Lazarides Feb 9 '11 at 4:26
up vote 8 down vote accepted

You can insert

Some verbatim code, but I'm not inspired,

inside a tabular, or any alignment, immediately after \\ (in fact, immediately after TeX's \cr, which is hidden in \\ in LaTeX).

LaTeX's tabular is probably the way to go in this case:

\begin{tabular}{lr}% choose whichever column specification you like
  Fruit & Price \\
  Fruit & Price \\
    Some code
  Fruit & Price \\
  Fruit & Price
share|improve this answer
I have no idea what this code does, but it works brilliantly :) – Chris R Feb 9 '11 at 5:13
It's ugly, but I have to admit it works well. – Will Robertson Feb 9 '11 at 6:18
@Will: it is ugly. I changed it to a LaTeX solution that seems neater. – Bruno Le Floch Feb 9 '11 at 6:26
looks much better now! To be honest, I didn't realise you could put verbatim inside a \noalign. Oops, me. – Will Robertson Feb 9 '11 at 11:50
@Will: I didn't realize it either, and I was trying a different way when I stumbled upon this fact in the TeXbook. – Bruno Le Floch Feb 9 '11 at 12:49

What defines the alignment of the fruit? Can you just write something like

  Peach & \$4.00 \\
  Banana & \$6.77

for each block? Otherwise, if you need to match up lengths through the document based on, say, the largest word in the column then check out the eqparbox package. You could write, e.g.,

  \noindent\eqparbox[b]{fruit}{#1}\qquad\$#2 \par

Some verbatim code, but I'm not inspired,
sorry. &*#^^7


And then compile the document twice.

share|improve this answer
Thanks, it was the latter case - I was about to look into eqparbox then Bruno posted a solution that worked very well for me. – Chris R Feb 9 '11 at 5:14

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.