开发者

Advanced table in LaTeX with multiline cells

I'm trying to achieve something like thi开发者_StackOverflow社区s in LaTeX: http://sorenhaagerup.dk/files/table-sample.pdf (sample made in OpenOffice.org)

The most important part is the multiline verbatim-environment inside a cell. Is this possible at all?

I will be very grateful to any answers, since this has been bugging me quite a lot.


I have looked at your table and rebuild the first part of it - the "var" part. Since building tables with latex isn't my speciality the code looks pretty messy but does the job. The relevant packages are multirow - to achieve the nested table - and verbatim to get the verbatim environment you asked for. As you will see I had to use additional minipages the handle the proper placing of the verbatim environment. You can comment them out to see the difference. Furthermore I started the table with the following line

\begin{tabular}{|l|l|l|p{8cm}|}

otherwise if you don't use p-aragraph colums for the last column you might get some errors using specified environments inside the columns.

As references I would suggest the latex-wikibooks which have additional examples and tips.

Here is the whole .tex example:

\documentclass[11pt]{article}
\setlength{\textwidth}{20.0cm}

\usepackage{verbatim} 
\usepackage{multirow} 


\begin{document}

\begin{tabular}{|l|l|l|p{8cm}|}
  \hline
  Element & Type & Case & Template\\ \hline
  \multirow{4}{*}{} Var & id & escaping or diff. level & 
  \begin{minipage}[t]{\linewidth}
\begin{verbatim}
return [offset](\%ebp)
\end{verbatim} 
  \end{minipage} 
\\ \cline{3-4}
  &  & else &
  \begin{minipage}[t]{\linewidth}
\begin{verbatim}
return TEMP(n)
\end{verbatim} 
  \end{minipage} \\ \cline{2-4}
  & index & - &
  \begin{minipage}[t]{\linewidth}
\begin{verbatim}
a = A_var(var)
movl a, t1
// do runtimecheck 5
t2 = A_exp(exp)
movl t2, t3
addl $1, t3
return (t1, t3, 4)
\end{verbatim} 
  \end{minipage} \\ \cline{2-4}
  & field & - &
  \begin{minipage}[t]{\linewidth}
\begin{verbatim}
a = A_var(var)
movl a, t1 // hvis a ikke er temp 
// do runtimecheck 5
movl [offset], t3
return (t1, t3, 4)
\end{verbatim} 
  \end{minipage}
  \\ \hline
\end{tabular}

\end{document}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜