Tell me more ×
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'm trying to center a the content of a figure that has verbatim text in it, but the verbatim text is always right-aligned:

\begin{figure}
  \centering
  \begin{verbatim}
  some
  text
  here
  \end{verbatim}
  \caption{I wish this were centered}
\end{figure}
share|improve this question
3  
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 at 9:49
Thanks @egreg! I will check that out. – cam Feb 14 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 2 days ago

1 Answer

up vote 3 down vote accepted

The verbatimbox package also does this. Here's your example done that way:

\documentclass{article}
\usepackage{verbatimbox}
\begin{document}

\begin{verbbox}
  some
  text
  here
\end{verbbox}
\begin{figure}
  \centering
  \theverbbox
  \caption{I wish this were centered}
\end{figure}
\end{document}
share|improve this answer

Your Answer

 
discard

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.