Hello all,
I just have one line in verbatim:
\begin{verbatim}
the line
\end{verbatim}
And i would like to center it. It seems that \center, \centerline do not work here. I do not want to use minipage because the length of the line could change.
By the way, the reason why i insist to envelop a line within a verbatim is that i have other similar lines/paragraphs handled by verbatim. I would like to align their font size and face, etc.
Does anyone know the answer?
Thanks and regards
Tie CHENG
Text Formatting ⇒ center a text in verbatim
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
center a text in verbatim
Hi Tie,
you could use \verb:
Stefan
you could use \verb:
Code: Select all
Code, edit and compile here:
\documentclass[a4paper,10pt]{article}\begin{document}\centering\verb|the line|\end{document}
LaTeX.org admin
Re: center a text in verbatim
Your solution works very well, thank you very much, Stefan!
center a text in verbatim
I've just came across this problem. Why not use spaces to put text in middle in verbatim environment? Verbatim is basically what you see is what you get, isn't it? The proposed solution did not work for me as "\centering" centers everything afterwards. "{\centering \begin{Verbatim} ... } did not have any effect either.
- Ijon Tichy
- Posts: 640
- Joined: Mon Dec 24, 2018 10:12 am
center a text in verbatim
If you change the margins you would have to change the number of spaces. So this wouldn't be a good idea.
Code: Select all
Code, edit and compile here:
\documentclass[a4paper,10pt]{article}\usepackage{verbatim}\makeatletter\newenvironment{centeredverbatim}{\expandafter\verbatim\centering}{\endverbatim}\makeatother\begin{document}\begin{centeredverbatim}BimmVerbatimusingautomatic \centeringThisLines\end{centeredverbatim}\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. 
