我正在创建一个表格,其中有一些单元格包含itemize
环境。对于给定的行,我有零个或两个单元格包含此环境并协同工作。但是,第一个单元格的项目文本通常比第二个单元格的项目文本长。
我正在寻找一种方法来实现此表,其中项目的项目要点分别位于相同的高度。图片比长篇描述更好,这里是:
我希望短文 1 的要点与第一个长文的要点处于同一级别,短文 2 及其相关项目也是如此。
以下是用于生成该表的代码:
\documentclass{article}
\usepackage{enumitem}
\usepackage{array}
\begin{document}
\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item This is a first long long long item, spanning on two lines
\item And here comes a second one lon long item
\end{itemize} & Some text which can be either long or short, there is no general rule &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1
\item Short 2
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}
注 1我想要一个高度尽可能紧凑的解决方案
笔记2我使用m{<value>}
列样式是因为不同行的最长单元格并不总是相同的。
注 3我知道表格很丑,应该删除垂直线以使其更符合可读性和读者友好的解决方案,但这是一个强制性的模板......太糟糕了......
编辑\multirow
Trylks 建议在非列表单元格中使用组合,并将列表单元格拆分为更多单元格。这确实解决了项目垂直对齐的问题,但也造成了其他单元格的错位。
MWE 的编辑建议
\documentclass{article}
\usepackage{enumitem}
\usepackage{array}
\usepackage{multirow}
\begin{document}
\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
\multirow{2}{*}{1} &
\begin{itemize}[leftmargin=0.3cm]
\item This is a first long long long item, spanning on two lines
\end{itemize}
& \multirow{2}{*}{Some text which can be either long or short, there is no general rule} &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1
\end{itemize}
& \multirow{2}{*}{Some short text}\\
& \begin{itemize}[leftmargin=0.3cm]
\item And here comes a second one lon long item
\end{itemize}
& &
\begin{itemize}[leftmargin=0.3cm]
\item Short 2
\end{itemize}
& \\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}
以及相应的输出:
编辑2jfbu 提出了一个似乎对上述情况有效的解决方案(参见他的回答),但这只是巧合。如果一个项目的文本长度超过两行,它也会崩溃。参见 MWE 及其输出:
\documentclass{article}
\usepackage{enumitem}
\usepackage{array}
\begin{document}
\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut This is a first long long long item, spanning on two lines. This is a first long long long item, spanning on two lines. This is a first long long long item, spanning on two lines \strut
\item \strut And here comes a second one lon long item \strut
\end{itemize} & Some text which can be either long or short, there is no general rule &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut Short 1 \hfill\break \strut
\item \strut Short 2 \hfill\break \strut
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}
答案1
我还是推荐的\strut
。
\documentclass{article}
\usepackage{enumitem}
\usepackage{array}
\makeatletter
\def\LUDOVIC {}
\def\LUDOvic {\par\xdef\LUDOVIC{\LUDOVIC {\the\prevgraf}}}
\def\ludoVIC {\par\expandafter\ludovic@ \LUDOVIC\relax }
\def\ludovic@ #1#2\relax {\gdef\LUDOVIC {#2}%
\vspace{\numexpr #1-\prevgraf\relax\baselineskip}}
\makeatother
\begin{document}
\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item This is a first long long long item, spanning on many
lines. This is a first long long long item, spanning on many
lines. This is a first long long long item, spanning on many
lines. This is a first long long long item, spanning on many
lines. \LUDOvic
\item And here comes a second one long long
item. And here comes a second one long long
item. And here comes a second one long long
item. And here comes a second one long long
item. And here comes a second one long long
item. \LUDOvic
\item And here is a third one. And here is a third one. And here is a third
one. And here is a third one. And here is a third one. \LUDOvic
\item And a fourth one. \LUDOvic
\end{itemize} & Some text which can be either long or short, there is no general rule &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1\ludoVIC
\item Short 2\ludoVIC
\item Short 3\ludoVIC
\item Short 4\ludoVIC
\end{itemize} & Some short text\\ \hline
\end{tabular}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item This is a first long long long item, spanning on many
lines. This is a first long long long item, spanning on many
lines. \LUDOvic
\item And here comes a second one long long
item. And here comes a second one long long
item. And here comes a second one long long
item. \LUDOvic
\end{itemize} & Some text which can be either long or short, there is no general rule &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item Short 1\ludoVIC
\item Short 2\ludoVIC
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}
输出:
第一个快速起草的答案:
这似乎有效。
\documentclass{article}
\usepackage{enumitem}
\usepackage{array}
\begin{document}
\begin{table}[H]
\begin{center}
\begin{tabular}{| m{0.3cm} | m{5.5cm} | m{4cm} | m{1.8cm} | m{1cm}|}
\hline
1 &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut This is a first long long long item, spanning on two lines\strut
\item \strut And here comes a second one lon long item\strut
\end{itemize} & Some text which can be either long or short, there is no general rule &
\begin{itemize}[leftmargin=0.3cm]\itemsep0pt
\item \strut Short 1\hfill\break \strut
\item \strut Short 2\hfill\break \strut
\end{itemize} & Some short text\\ \hline
\end{tabular}
\end{center}
\end{table}
\thispagestyle{empty}
\end{document}