Two column table, enumerate first column but not second
You could simply use your own counter:
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}
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
:
\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.
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}