Take the 2-minute tour ×
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.

Here is an code that i want to display in verbatim mode.

But the displayed code is locate at the left of the page.

 \begin{singlespace}
  \begin{verbatim}
 Imread('filename');
 \end{verbatim}
 \end{singlespace}

How too locate it in the centre of the page?

share|improve this question
add comment

2 Answers 2

Use fancyvrb:

\documentclass{article}
\usepackage{kantlipsum}
\usepackage{fancyvrb}
\usepackage{setspace}
\onehalfspacing

\newenvironment{CVerbatim}
 {\singlespacing\center\BVerbatim}
 {\endBVerbatim\endcenter}

\begin{document}
\kant[1]
\begin{CVerbatim}[fontsize=\small]
This is \verbatim text
which you will find centered on the page
\end{CVerbatim}
\kant[2]
\end{document}

The option fontsize=\small is just to show that you can pass CVerbatim any fancyvrb option.

enter image description here

share|improve this answer
add comment

Stuff the verbatim in a box first. The optional argument allows you to "condition" the verbatim text, as well.

\documentclass{article}
\usepackage{verbatimbox}
\textheight=1cm
\begin{document}
\begin{verbbox}[\tiny]
This is \verbatim text
which you will find centered on the page
\end{verbbox}
\centering\theverbbox
\end{document}

enter image description here

p.s. I presume you meant horizontally centered.

share|improve this answer
add comment

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.