2

I want to insert some raw text and used verbatim in the cell of a tabular.

Here is the code:

\documentclass{article}

\begin{document}
\begin{tabular}{p{0.45\textwidth}|p{0.45\textwidth}}
\hline column 1:  &  column 2:   \\ 
\hline
\begin{verbatim}
verbatim 1
 verbatim 2
\end{verbatim}&
\begin{verbatim}
verbatim 1
 verbatim 2
\end{verbatim}\\
\hline
normal 1& normal 2\\
\hline
\end{tabular}
\end{document}

Here is the output:

enter image description here

There are a empty line before and after the verbatim text...

How can I remove those empty lines?

1

The fancyvrb package provides a BVerbatim environment which has no space around the enclosed material:

Sample output

\documentclass{article}

\usepackage{fancyvrb}

\begin{document}
\showoutput
\begin{tabular}{p{0.45\textwidth}|p{0.45\textwidth}}
\hline column 1:  &  column 2:   \\ 
\hline
\begin{BVerbatim}
verbatim 1
 verbatim 2
\end{BVerbatim}
&
\begin{BVerbatim}
verbatim 1
 verbatim 2
\end{BVerbatim}
\\
\hline
normal 1& normal 2\\
\hline
\end{tabular}
\end{document}
1

Use \verb|text| instead of \begin{verbatim} \end{verbatim}

Code:

\documentclass{article}

\begin{document}
\begin{tabular}{p{0.45\textwidth}|p{0.45\textwidth}}
\hline column 1:  &  column 2:   \\ 
\hline
\verb|verbatim 1|

\verb|verbatim 2|&
\verb|verbatim 1|

\verb|verbatim 2|\\
\hline
normal 1& normal 2\\
\hline
\end{tabular}
\end{document}

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.