基本问题是我需要在表格单元格中进行枚举。特殊要求是让单元格(或整个列)中的文本与此单元格顶部对齐。
我的第一个方法是:
\begin{table}[h!]
\begin{tabular}{r|l}
\textbf{Input} &
some text\\
\textbf{Work} &
\parbox{\linewidth}{\begin{enumerate}
\item The first step
\item The second step which is very long, so this text is more than the table width and should be broken .
\end{enumerate}}\\
\textbf{Output}: & some other text.\\
\end{tabular}
\end{table}
如您所见,左列中的文本未顶部对齐。我尝试了多种方法,例如这个但无法修复它。
我的第二种方法是使用嵌套表:
\begin{table}[h!]
\begin{tabular}{r|l}
\textbf{Input} &
some text\\
\textbf{Work} &
\begin{tabular}[t]{ll}
1. & The first step \\
2. & The second step which is very long, so this text is more than the table width and should be broken.\\
\end{tabular}
\\
\textbf{Output}: & some other text.\\
\end{tabular}
\end{table}
我试图修复内表的宽度(参见这里),但这也不起作用。
如何在表格中枚举单元格与左上对齐?谢谢!
答案1
我建议您 (a) 使用tabularx
环境,以避免计算第二列宽度的繁琐工作,以及 (b) 使用minipage[t]
环境来包裹enumerate
环境。
\documentclass{article}
\usepackage{enumitem}
\usepackage{tabularx} % for 'tabularx' env. and 'X' column type
\begin{document}
\begin{table}[h!]
\begin{tabularx}{\textwidth}{ @{} r | X @{} }
\textbf{Input} & Some text.\\
\textbf{Work} &
\begin{minipage}[t]{\linewidth}
\raggedright % optional
\begin{enumerate}[noitemsep]
\item The first step
\item The second step is very long, so this text exceeds the
table width and should be line-broken automatically.\strut
\end{enumerate}
\end{minipage}\\
\textbf{Output} & Some other text.\\
\end{tabularx}
\end{table}
\end{document}
答案2
%Preamble
\usepackage{multirow}
%______________________%
\begin{tabular}{r|l}
\textbf{Input} &
some text\\
\multirow{-3}{*}{\textbf{Work}} &
\parbox{\linewidth}{\begin{enumerate}
\item The first step
\item The second step which is very long, so this text is more than the table width and should be broken .
\end{enumerate}}\\
\textbf{Output}: & some other text.\\
\end{tabular}