3

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.

8

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}
| improve this answer | |

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.