我有一张表格,其中每一列的每个单元格都包含列表,并且我坚持使用垂直线。目前,我有以下 MWE:
\documentclass[11pt]{article}
\usepackage[margin=20mm]{geometry}
% \usepackage{booktabs}
\usepackage{enumitem}
\usepackage{longtable}
\begin{document}
\begin{longtable}{|p{0.05\textwidth}|p{.75\textwidth}|p{0.10\textwidth}|}
% \toprule
\hline
Serial No.\ & Assignment Name & Date \\
% \midrule
\hline
1
&
\begin{minipage}[t]{\linewidth}
Foo bar
\begin{enumerate}[nosep,after=\strut]
\item foo
\item foo
\item bar
\item bar
\end{enumerate}
\end{minipage}
&
10.01.2022\\
% \midrule
\hline
2
&
\begin{minipage}[t]{\linewidth}
\begin{enumerate}[nosep, after=\strut, label=(\Alph*)]
\item
Given two sequences:
\[ x_1 = \{\mathbf{2}, 2, 1, 2 \} \]
\[ x_2 = \{\mathbf{-2}, -1, 3, 2 \} \]
\end{enumerate}
% other items...
Find their convolution
\end{minipage}
&
17.01.2022\\
%\bottomrule
\hline
\end{longtable}
\end{document}
我有两个版本:
我正在寻找一个介于两者之间的:
- 给我适当的间距
- 消除不连续的垂直线。
(它需要是长表,因为还有更多条目,它们加起来至少会跨越 3 页。)
答案1
在该包的帮助下tabularray
:
要调整水平线和文本之间的间距,请使用abovesep
和belowsep
和 键。(默认值为2pt
。)
\documentclass[11pt]{article}
\usepackage[margin=20mm]{geometry}
\usepackage{enumitem}
\newlist{tabenum}{enumerate}{1}
\setlist[tabenum]{label*=\arabic*.,
leftmargin=*,
nosep,
before=\begin{minipage}[t]{\hsize},
after=\end{minipage}}
\usepackage{tabularray}
\UseTblrLibrary{varwidth}
\begin{document}
\begin{longtblr}{colspec={l X l}, hlines, vlines, measure = vbox}
{Serial\\ No.} & Assignment Name & Date \\
1
&
Foo bar
\begin{tabenum}
\item foo
\item foo
\item bar
\item bar
\end{tabenum}
&
10.01.2022\\
2
&
\begin{tabenum}[label=(\Alph*)]
\item
Given two sequences:
\[ x_1 = \{\mathbf{2}, 2, 1, 2 \} \]
\[ x_2 = \{\mathbf{-2}, -1, 3, 2 \} \]
\end{tabenum}
%other items...
Find their convolution
&
17.01.2022\\
\end{longtblr}
\end{document}
答案2
您对垂直线的看法是错误的,但这只是个人观点。
您不需要使用小页面,而是需要删除列表之前或之后的虚假空白行。
\documentclass[11pt,draft]{article}
\usepackage[margin=20mm]{geometry}
\usepackage{enumitem}
\usepackage{longtable}
\usepackage{amsmath}
\begin{document}
\begin{longtable}{|c|p{.75\textwidth}|l|}
\hline
\begin{tabular}[t]{@{}c@{}}Serial \\ No.\end{tabular} & Assignment Name & Date \\
\hline
1 &
Foo bar
\begin{enumerate}[nosep,after=\vspace*{-\baselineskip}]
\item foo
\item foo
\item bar
\item bar
\end{enumerate} &
10.01.2022\\
\hline
2 &
\begin{enumerate}[nosep, wide, label=(\Alph*),before=\vspace*{-\baselineskip}]
\item Given two sequences:
\begin{gather*}
x_1 = \{\mathbf{2}, 2, 1, 2 \} \\
x_2 = \{\mathbf{-2}, -1, 3, 2 \}
\end{gather*}
\item Given two sequences:
\begin{gather*}
x_1 = \{\mathbf{2}, 2, 1, 2 \} \\
x_2 = \{\mathbf{-2}, -1, 3, 2 \}
\end{gather*}
\end{enumerate}
Find their convolution &
17.01.2022\\
\hline
\end{longtable}
\end{document}
答案3
也许这个带有cellspace
软件包的解决方案对您来说就足够了。S
默认情况下,此软件包可确保在带有以字母为前缀的说明符的列中单元格顶部和底部的垂直间距最小(或者C
如果您加载siunitx
,或使用该选项选择任何您想要的字母column=some letter
)。
由于您使用了列类型,我还删除了 minipage
这里不必要的环境p
。
\documentclass[11pt]{article}
\usepackage[margin=20mm]{geometry}
\usepackage{enumitem}
\usepackage{longtable}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{8pt}
\setlength{\cellspacebottomlimit}{8pt}
\begin{document}
\begin{longtable}{|p{0.05\textwidth}|S{p{.75\textwidth}}|p{0.10\textwidth}|}
% \toprule
\hline
Serial No.\ & Assignment Name & Date \\
% \midrule
\hline
1
&
Foo bar
\begin{enumerate}[nosep,after=\strut]
\item foo
\item foo
\item bar
\item bar
\end{enumerate}
&
10.01.2022\\
\hline
%
2
& \begin{enumerate}[nosep, after=\strut, label=(\Alph*)]
\item
Given two sequences:
\[ x_1 = \{\mathbf{2}, 2, 1, 2 \} \]
\[ x_2 = \{\mathbf{-2}, -1, 3, 2 \} \]
\end{enumerate}
% other items...
Find their convolution
&
17.01.2022 \\
\hline
\end{longtable}
\end{document}
答案4
我会(a)去掉所有垂直条 - 它们是不需要的,也不会被遗漏 - 并且(b)计算中间列的宽度作为残差,以确保列的宽度最大化。
\documentclass[11pt]{article}
\usepackage[margin=20mm]{geometry}
\usepackage{booktabs,enumitem,longtable,amsmath}
\newlength\mylenA
\settowidth\mylenA{Serial No.}
\newlength\mylenB
\settowidth\mylenB{10.01.2022}
\begin{document}
\begin{longtable}{@{} p{\mylenA}
p{\dimexpr\textwidth-\mylenA-\mylenB-4\tabcolsep\relax}
p{\mylenB} @{}}
\toprule
Serial No. & Assignment Name & Date \\
\midrule
\endhead
\bottomrule
\endlastfoot
1
&
\begin{minipage}[t]{\linewidth}
Foo bar
\begin{enumerate}[nosep,after=\strut]
\item foo
\item foo
\item bar
\item bar
\end{enumerate}
\end{minipage}
&
10.01.2022 \\
\midrule
2
&
\begin{minipage}[t]{\linewidth}
\begin{enumerate}[nosep, after=\strut, label=(\Alph*)]
\item
Given two sequences:
\[
\begin{aligned}
x_1 &= \{\mathbf{2}, 2, 1, 2 \} \\
x_2 &= \{\mathbf{-2}, -1, 3, 2 \}
\end{aligned}
\]
% other items...
Find their convolution
\end{enumerate}
\end{minipage}
&
17.01.2022\\
\end{longtable}
\end{document}