TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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 am trying to center align the content of a figure that has verbatim text in it. But the verbatim text is always right-aligned:

  \caption{I wish this were centered}
share|improve this question
Welcome to TeX.sx! A verbatim environment is always typeset on full length. You may want to look at the fancyvrb package and its BVerbatim environment. – egreg Feb 14 '13 at 9:49
Thanks @egreg! I will check that out. – cam Feb 14 '13 at 12:45
@cam Don't forget to select the answer if it worked for you. Points for having their answer selected helps motivate people to continue to answer questions. If it didn't work, perhaps you can provide additional details, or submit your own answer if you came up with another solution. – sh1ftst0rm May 16 '13 at 15:02
@egreg - I tried BVerbatim, but it seems that boxwidth=auto doe not work correctly but always yields the full page width. I have to specify an explicit dimension in order for the centering to work. Any clues on this? I would prefer BVerbatim if this worked. – Emit Taste Nov 5 '13 at 20:13
up vote 12 down vote accepted

The verbatimbox package also does this. Here's an example done that way (Fig. 1).

UPDATE: In Fig. 2, it is shown how you can import multiple verbatim snippets into a single figure (or table) using the myverbbox environment, wherein you give unique names to the snippets. Also, the optional argument can be used to condition the verbatim text, in this case, to \small.


  some \verbatim
  text here
  \caption{I wish this were centered}

\valph & $\alpha$\\
\vbet  & $\beta$
\caption{Some Greek macros for math mode}

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.