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.

I'm trying to simulate an effect that is very easy to do in WYSIWYG environments, namely having a table with some cells containing somewhat complex multi-line entities. For instance, consider the following table (created with OpenOffice):

table

In particular, I'm concerned about the middle cell at the bottom there; I can't find a way to create that in LaTeX using the table environment. The problem seems to be that it has no way of distinguishing the \\ linebreak as referring to the contents of the cell, or to the structure of the table.

I know about the multirow package and how it theoretically allows things like this, but only in the clumsiest of ways; I would have to set something like a colspan on every row of that source. If I were to add a line to the beginning of the listing, I'd have to manually shift each row after that down.

What I would love is some sort of easy thing to wrap my code in which makes it all belong to a single table row. I feel certain there must be a way to do that, but Google wasn't being very helpful, so I thought I'd ask here.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

You can use lstlising environment from listings package to replace verbatim.

For example:

\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}
\begin{tabular}{|c|c|}
\hline
\begin{lstlisting}
!@#$%^$%&
!@#$%^$%&
\end{lstlisting}
&
\begin{lstlisting}
!@#$%^$%&
!@#$%^$%&
\end{lstlisting}
\\ \hline
\begin{lstlisting}
!@#$%^$%&
!@#$%^$%&
\end{lstlisting}
&
\begin{lstlisting}
!@#$%^$%&
!@#$%^$%&
\end{lstlisting}
\\ \hline
\end{tabular}
\end{document}
share|improve this answer
    
Works like a charm :) Thanks a lot, Leo! –  Adrian Petrescu Jan 5 '11 at 21:11
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.