5

I want to center a box containing a verbatim environment. The (almost)MWE below is my attempt to use the answer at Center-align the verbatim environment .

\documentclass{article}
\usepackage{verbatimbox}
\usepackage{amsmath}

\begin{document}
The table at \verb!http://www.census.gov/govs/state/10lottery.html!
lists the following data for the 2010 Texas lotteries:

\begin{center}
\begin{verbbox}
  Income               Apportionment of funds
(ticket sales      Prizes  Administration  Proceeds
  excluding                               available
  commissions)
  3,542,210       2,300,182   184,980     1,057,048
\end{verbbox}
\end{center}

Since
%
\begin{equation*}
\frac{2,300,182}{3,542,210} = 0.649363533 \approx 65\%
\end{equation*}
%
Texas returned 65 cents on the dollar in lottery payouts in 2010 --
three cents more than the national average.

\end{document}

In the output, the boxed text has disappeared:

enter image description here

6

You have to issue \theverbbox in order to print the verbatim text. However, the verbbox environment shouldn't be inside center.

I also add how to do it with fancyvrb and its BVerbatim environment. I also use \url for the URL.

\documentclass{article}
\usepackage{verbatimbox,fancyvrb,url}
\usepackage{amsmath}

\begin{document}

The table at \url{http://www.census.gov/govs/state/10lottery.html}
lists the following data for the 2010 Texas lotteries:
\begin{verbbox}
  Income               Apportionment of funds
(ticket sales      Prizes  Administration  Proceeds
  excluding                               available
  commissions)
  3,542,210       2,300,182   184,980     1,057,048
\end{verbbox}
\begin{center}
\theverbbox
\end{center}

Since
\begin{equation*}
\frac{2,300,182}{3,542,210} = 0.649363533 \approx 65\%
\end{equation*}
Texas returned 65 cents on the dollar in lottery payouts in 2010 --
three cents more than the national average.

\begin{center}
\begin{BVerbatim}
  Income               Apportionment of funds
(ticket sales      Prizes  Administration  Proceeds
  excluding                               available
  commissions)
  3,542,210       2,300,182   184,980     1,057,048
\end{BVerbatim}
\end{center}

\end{document}

enter image description here

  • I knew about \url but omitted to minimize my example. I know about using \centering instead of a center environment for figures. Why not use it here? – Ethan Bolker Dec 2 '13 at 21:23
  • @EthanBolker With center you leave some vertical space fore and aft the verbatim part. This is the reason why \centering should be preferred in a figure or table environment, but not here. – egreg Dec 2 '13 at 21:24
  • I see. The \verbbox is defined outside the center environment but the \theverbox is inside. – Ethan Bolker Dec 2 '13 at 21:28
  • @EthanBolker If it's inside, the last line disappears. – egreg Dec 2 '13 at 21:30
  • I noticed! I find that weird. I'm sure digging into source would explain why, but that's more than I need to know. – Ethan Bolker Dec 2 '13 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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