0

MWE:

\documentclass{article}
\usepackage{array,etoolbox,lipsum}

\makeatletter
\preto{\@verbatim}{\topsep=0pt \partopsep=0pt}
\makeatother
\begin{document}

\begin{table}[ht]
  \begin{tabular}{>{\ttfamily}p{3cm}|p{3cm}}
    \vspace{-6pt} % NOTE!
    \begin{verbatim}
lines within verbatim 
environment. Let's add
some more lines
    \end{verbatim}
    \vspace{-\baselineskip} % NOTE!
    ordinary lines out of
    verbatim environment 
    &
  \lipsum[1][1-2]\\
  \end{tabular}\\
\end{table}

\noindent Before verbatim
\begin{verbatim}
\documentclass{article}
\begin{document}
\end{document}
\end{verbatim}
After verbatim

\end{document}

Output:

enter image description here

I looked for a solution that removes spaces before and after verbatim. Yes I found it (see line \preto) but, as you can see from the example above, it will not work in tabular's cell if I remove \vspaces. I empirically "hacked" the right values but I would like to understand what do I wrong. I want to use \verbatim just as is and see no odd leading spaces before or after in case of table cells.

0 Answers0