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 need to have a two column table, where the first column contains enumerations and the second take plain text. For example,

Column 1           Column 2
1. Step 1          Reason 1
2. Step 2          Reason 2

I've tried a couple couple combinations of tabular with the enumerate environment, but nothing works. Can someone show me how to do this?

share|improve this question
    
Will the vertical lengths of Step X and Reason X differ? Or are they going to be the same? –  Werner Jan 22 '12 at 20:30
    
They will be the same. –  gsingh2011 Jan 22 '12 at 20:54
add comment

3 Answers

up vote 4 down vote accepted

In order to include standard list environments in a tabular you need to "box" it. The minipage environment provides a good means to do so. Additionally, item labelling is easily customizable via enumitem:

enter image description here

\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\begin{document}
\begin{tabular}{c c}
  Column 1 & Column 2 \\ \hline \\[-\dimexpr\normalbaselineskip-\jot]
  \begin{minipage}{0.3\textwidth}\begin{enumerate}[label={\strut\arabic*.}]
    \item First step
    \item Second step
    \item Last step
  \end{enumerate}\end{minipage} &
  \begin{minipage}{0.3\textwidth}\begin{enumerate}[label={\strut}]
    \item First reason
    \item Second reason
    \item Last reason
  \end{enumerate}\end{minipage} \\ \hline
\end{tabular}
\end{document}

The Column 1 list has a regular list form, while the list in Column 2 is set without label. I've added a \strut to both labels to ensure that short items without descenders have proper depth. Also, since minipage boxing is known for removing proper vertical spacing, I've added a \jot gap between the column headings and the tabular body. This is achieved by adding an extra row of height \jot-\normalbaselineskip (via \dimexpr). More on the minipage "behaviour" and possible corrections can be obtained from: How to keep a constant baselineskip when using minipages (or \parboxes)?

The advantage of still having a list within the table is that the standard spacing (labelwidth, labelsep, itemindent, ...) for longer items still hold. You may want to remove the label separation as well for Column 2, but this depends on your actual application. All these settings can be changed on the fly. Read more about it in the enumitem documentation.

share|improve this answer
    
Thanks. This looks great. One thing to note about this solution is if the items in column one need to be lined up with the items in column two and one of the items in column one is too long and takes multiple lines, the item in column two will not align with it. For my purposes, I simply made sure that everything fit on one line. –  gsingh2011 Jan 22 '12 at 22:58
    
@gsingh2011: That's correct; hence my original question/comment about the contents being vertically equivalent. –  Werner Jan 23 '12 at 1:12
    
I honestly don't like this solution. Imagine for example that you include $\sum_{i=0}^n n^2$ in the Reason 1. Then you get the baseline-grid still corrupted (even you mention some tricks for that). You can get a proper spacing of the table redefining the spacing commands of the table using those of the item environments. –  tohecz Jan 23 '12 at 9:23
    
@tohecz: You are more than welcome to suggest a better solution which suggests a better visual appearance in general. –  Werner Jan 23 '12 at 15:21
    
@Werner: I've just added my answer as a seperate one. I did not have LateX at the computer so I could not make the solution. –  tohecz Jan 23 '12 at 23:58
add comment

You could simply use your own counter:

enter image description here

Note:

  • As @egreg commented, it is better to use \theNumber instead of \the\value{Number}: by changing the definition of the former, one can change the format in the table without intervening on each cell. See What is the proper method of accessing a counter?

Code:

\documentclass{article}

\newcounter{Number}
\newcommand{\Item}{\stepcounter{Number}\theNumber.~}

\begin{document}
\begin{tabular}{c c}\setcounter{Number}{0}
    Column 1      &  Column 2\\
    \Item Step 1  &  Reason 1\\
    \Item Step 2  &  Reason 2
\end{tabular}
\end{document}
share|improve this answer
2  
It's better to use \theNumber instead of \the\value{Number}: by changing the definition of the former, one can change the format in the table without intervening on each cell. –  egreg Jan 22 '12 at 20:59
    
@egreg: Good point. Have added that to the solution. –  Peter Grill Jan 22 '12 at 23:03
add comment

I used the idea of Peter Grill and made a complex, nicely looking solution, comments are in the code. Me personally, I consider the Table 2 to be better (it's the one with p{.4\textwidth}).

\documentclass{article}

% tabularx for the ! command, booktabs for the rules and spacing
\usepackage{tabularx,booktabs}

% counter for the items
\newcounter{rowcnt}

% this macro typesets the number
\def\tableitem{\vspace{\itemsep}\ \stepcounter{rowcnt}\therowcnt.\ }

\begin{document}

\begin{table}
 % horizontal center 
\centering
 % reset counter to zero
\setcounter{rowcnt}{0}
 % the ! command places its argument at the very beginning of every line
\begin{tabular}{!{\tableitem} cc}
\toprule
 % multicolumn just to kill the ! command on this line
\multicolumn{1}{c}{\bf Steps}      &  \bf Reasons \\\midrule
  Step 1  &  Reason 1 longer \\
  Step 2 longer  &  Reason 2 \\
 % the [-\itemsep] is acutally a parameter of \\ above and kills the \itemsep of the last row of the table
[-\itemsep]\bottomrule
\end{tabular}
\caption{Steps and reasons}
\end{table}

\begin{table}
\centering
\setcounter{rowcnt}{0}
\begin{tabular}{!{\tableitem} p{.4\textwidth} p{.4\textwidth}}
\toprule
\multicolumn{1}{c}{\bf Steps}      &  \multicolumn{1}{c}{\bf Reasons} \\\midrule
  Step $\sum_{k=1}^\infty2^{-k}$  &  We know that the sum converges to a number $1$. \\
  Step $\sum_{k=0}^\infty2^{-k}$  &
    We added $2^0=1$ to the previous sum, and even a small child know that $1+1$ equal to $2$, which is a number in front of this line.\\
[-\itemsep]\bottomrule
\end{tabular}
\caption{Second, identical table, we just use \texttt{p\{.4\textbackslash textwidth\}} as column specification, for long contents}
\end{table}

\begin{table}
\centering
\begin{tabular}{!{\tableitem} cc}
\toprule
\multicolumn{1}{c}{\bf Steps}      &  \bf Reasons \\\midrule
Step X  &  Reason X longer \\
Step Y longer  &  Reason Y \\
[-\itemsep]\bottomrule
\end{tabular}
\caption{Third table, we removed the command \texttt{\textbackslash setcounter\{rowcnt\}\{0\}} so that the numbering continues}
\end{table}

\end{document}
share|improve this answer
1  
Good use of array's column declaration !. –  Werner Jan 24 '12 at 0:12
    
@Werner: honestly, it is a twisted way to place something of the left of the first centered table column. Well, TeX is more than 30 years old hence it needs the 30-year-old approach ;) –  tohecz Jan 24 '12 at 0:40
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.