在表格中不同高度的行后添加相等的空间

在表格中不同高度的行后添加相等的空间

我想制作一个表格,可以在许多行(但不是所有行)后添加 1em 的空格。行的高度各不相同(因为它们包含不同长度的内容)。我试图通过在每个换行符后“添加粘连”(我认为这是术语)来添加额外的空间,即\\ [1em]

在我的旧电脑(我认为是 MacTeX 2016)上,这个功能曾经可以正常工作,但现在我在新机器(MacTeX 2018)上安装了 LaTeX,它就不能正常工作了。所以也许我安装错了什么,或者我使用了其他版本的东西……

这似乎是在每行的第一行底部添加 1em 的空间,所以如果行一开始只有一行高,则似乎什么也不会发生。

有人能解释一下这里发生了什么,并提出解决方案吗?谢谢!

梅威瑟:

\documentclass[letterpaper,11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{longtable}
\usepackage{tabu}

\newcolumntype{L}{>{\raggedright}p{1in}}
\newcolumntype{R}{>{\raggedright\arraybackslash}p{5.5in}}

\begin{document}

\begin{longtable}{ @{} L @{} R @{} }

One & Long entry, long enough to span two lines! Long entry, long enough to span two lines! Long entry, long enough to span two lines! \\ [1em]

Two & Entry that only spans one line, correctly has 1em space after it. \\ [1em]

Three & Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! \\ [1em]

Four & Another short entry... \\

\end{longtable}

\end{document}

对我来说,这看起来像:

在此处输入图片描述

答案1

如果您想要所有行的空间,最简单的方法是不要使用\\可选参数,而是调整表格间距,例如

\documentclass[letterpaper,11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{longtable}
%\usepackage{tabu}
\usepackage{array,}

\newcolumntype{L}{>{\raggedright}p{1in}}
\newcolumntype{R}{>{\raggedright\arraybackslash}p{5.5in}}

\begin{document}

\setlength\extrarowheight{1em}
\begin{longtable}{ @{} L @{} R @{} }

One & Long entry, long enough to span two lines! Long entry, long enough to span two lines! Long entry, long enough to span two lines! \\ 

Two & Entry that only spans one line, correctly has 1em space after it. \\ 

Three & Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! \\ [1em]

Four & Another short entry... \\

\end{longtable}

\end{document}

对于一次性间距调整,可以使用\addlinespace命令booktabs

\documentclass[letterpaper,11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{longtable}
%\usepackage{tabu}
\usepackage{array,booktabs}

\newcolumntype{L}{>{\raggedright}p{1in}}
\newcolumntype{R}{>{\raggedright\arraybackslash}p{5.5in}}

\begin{document}

\begin{longtable}{ @{} L @{} R @{} }

One & Long entry, long enough to span two lines! Long entry, long enough to span two lines! Long entry, long enough to span two lines! \\ 

\addlinespace[1em]

Two & Entry that only spans one line, correctly has 1em space after it. \\ 

\addlinespace[1em]

Three & Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! \\ 

Four & Another short entry... \\

\end{longtable}

\end{document}

答案2

您可以使用\addlinespacefrom booktabs,(本地)将其默认值设置为 1em:

\documentclass[letterpaper, 11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{longtable,booktabs}
\usepackage{tabu}

\newcolumntype{L}{>{\raggedright}p{1in}}
\newcolumntype{R}{>{\raggedright\arraybackslash}p{5.5in}}

\begin{document}
{\setlength{\defaultaddspace}{1em}
\begin{longtable}{ @{} L @{} R @{} }

One & Long entry, long enough to span two lines! Long entry, long enough to span two lines! Long entry, long enough to span two lines! \\
\addlinespace

Two & Entry that only spans one line, correctly has 1em space after it. \\ [1em]

Three & Long entry, long enough to actually span three lines! Long entry, long enough to actually span three lines! Long entry, long enoughto actually span three lines! Long entry, long enough to actually span three lines!
\\
\addlinespace

Four & Another short entry... \\

\end{longtable}
}
\end{document} 

在此处输入图片描述

相关内容