数组包破坏了自定义行距

数组包破坏了自定义行距

我想使用该array包创建一个固定宽度的表格,其中文本右侧不规则,类似于这个问题。不幸的是,即使只是包含array包也会破坏定义的能力自定义行间距(见下面的例子)。

我如何使用该array包但仍定义行之间的自定义间距?

\documentclass{article}

\usepackage{array}

\begin{document}

\begin{tabular*}{\textwidth}{p{10cm}}
    A simple line. \\[1cm]
    A longer text that spans multiple lines. A longer text that spans multiple
    lines. A longer text that spans multiple lines. A longer text that spans
    multiple lines. \\[1cm]
    \textbf{There should be more space before this line}.
\end{tabular*}

\end{document}

在此处输入图片描述

删除该行将\usepackage{array}得到预期的结果:

在此处输入图片描述

答案1

事实上,它似乎没有这个功能就可以工作,array这是由于包中修复的原始实现存在缺陷。\\[..]语法为行添加了额外的深度,在原始实现中,这是添加到表格的最后一个单元格中的,因此尽管它名义上会影响整行,但其效果取决于最后一列的类型,只有当最后一列是深度最大的列时,您才能获得所需的效果。请注意,如果我l在表格开头添加一列,您将获得显示的间距,但如果我l在行的末尾添加一列,间距就会消失。

\documentclass{article}

%\usepackage{array}

\begin{document}
\centering

\begin{tabular*}{\textwidth}{lp{10cm}}
    x&A simple line. \\[1cm]
    x&A longer text that spans multiple lines. A longer text that spans multiple
    lines. A longer text that spans multiple lines. A longer text that spans
    multiple lines. \\[1cm]
    x&\textbf{There should be more space before this line}.
\end{tabular*}

\bigskip

\begin{tabular*}{\textwidth}{p{10cm}l}
    A simple line.&x \\[1cm]
    A longer text that spans multiple lines. A longer text that spans multiple
    lines. A longer text that spans multiple lines. A longer text that spans
    multiple lines.&x \\[1cm]
    \textbf{There should be more space before this line}.&x
\end{tabular*}


\end{document}

在此处输入图片描述

您可以增加长度参数,使其比p列的深度更深,但是booktabs正如您所发现的,间距命令在这里提供了更好的界面。

答案2

我发现的一个可能的解决方案相关问题来自\addlinespace以下booktabs包裹:

\documentclass{article}

\usepackage{booktabs}
\usepackage{array}

\begin{document}

\begin{tabular*}{\textwidth}{p{10cm}}
    A simple line. \\ \addlinespace[1cm]
    A longer text that spans multiple lines. A longer text that spans multiple
    lines. A longer text that spans multiple lines. A longer text that spans
    multiple lines. \\ \addlinespace[1cm]
    \textbf{There should be more space before this line}.
\end{tabular*}

\end{document}

答案3

tblr环境的替代解决方案tabularray包:\\[dimen]无论如何都会在行下方添加垂直空间。

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{tblr}{p{10cm}X}
    A simple line. & Alpha \\[1cm]
    A longer text that spans multiple lines. A longer text that spans multiple
    lines. A longer text that spans multiple lines. A longer text that spans
    multiple lines. & Beta \\[1cm]
    \textbf{There should be more space before this line}. & Delta
\end{tblr}

\bigskip

\begin{tblr}{Xp{10cm}}
    Alpha & A simple line. \\[1cm]
    Beta & A longer text that spans multiple lines. A longer text that spans multiple
    lines. A longer text that spans multiple lines. A longer text that spans
    multiple lines. \\[1cm]
    Delta & \textbf{There should be more space before this line}.
\end{tblr}

\end{document}

在此处输入图片描述

相关内容