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.

  • To make the MWE compilable, the array, etoolbox and lipsum packages are missing. – leandriis Apr 1 at 10:23
  • The new V type column defined by egreg in an answer to a previous question should also work in your case. – leandriis Apr 1 at 10:26
  • I don't want to shift/affect all the column by defining some new type. Why couldn't it be solved just by affecting verbatim? – Timur Fayzrakhmanov Apr 1 at 12:52
  • You can use \verb instead. No extra lines there. – John Kormylo Apr 1 at 13:33
  • verb|something| doesn't allow line breaks. – Timur Fayzrakhmanov Apr 1 at 13:58

Your Answer

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

Browse other questions tagged or ask your own question.