longtable 和 \\ 的问题

longtable 和 \\ 的问题

代码如下:

\documentclass[a4paper,10pt]{article}

\usepackage{longtable}
\usepackage{tabularx}

\newcolumntype{L}{>{\raggedleft}p{0.1\textwidth}}
\newcolumntype{R}{p{0.80\textwidth}}

\begin{document}
\begin{longtable}{L!{---}R}
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.\\[10pt]
12 & asdf asdf asdf asdf asdf.\\[10pt]
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.\\[10pt]
\end{longtable}
\end{document}

输出为 在此处输入图片描述 也就是说,在每一行中,垂直间距 10pt 是从第一行开始计算的,而不是从最后一行开始计算的。例如,如果在第一行中输入 30pt 而不是 10pt,那么第一行和第二行之间就会出现垂直间距。我认为这个问题出现在更新 MikTeX 的一些软件包时。

有谁知道解决这个问题的方法吗?

谢谢

答案1

2种方式:

雇用\extrarowheight大批包裹

\documentclass[a4paper,10pt]{article}

\usepackage{longtable,array}
\usepackage{tabularx}
\newcolumntype{L}{>{\raggedleft}p{0.1\textwidth}}
\newcolumntype{R}{p{0.80\textwidth}}
\setlength\extrarowheight{10pt}
\begin{document}
\begin{longtable}{L!{---}R}
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.\\
12 & asdf asdf asdf asdf asdf.\\
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.\\
\end{longtable}
\end{document}

建造支柱

这里,我创建了\mystrut,您可以将其添加到每个第 3 列条目的末尾,代替\\[10pt]。人们可以选择一个简单的固定维度,如\newcommand\mystrut{\rule[-10pt]{0pt}{0pt}},但我却创建了一个维度表达式,以相当于\\[10pt]

\documentclass[a4paper,10pt]{article}

\usepackage{longtable}
\usepackage{tabularx}
\newcommand\mystrut{\rule[\dimexpr-\dp\strutbox-10pt\relax]{0pt}{0pt}}
\newcolumntype{L}{>{\raggedleft}p{0.1\textwidth}}
\newcolumntype{R}{p{0.80\textwidth}}

\begin{document}
\begin{longtable}{L!{---}R}
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf 
  asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf 
  asdf asdf asdf asdf asdf.\mystrut\\
12 & asdf asdf asdf asdf asdf.\mystrut\\
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.\mystrut\\
\end{longtable}
\end{document}

任何一种方法都会产生以下输出(在表格开头加上/减去一些前导空格)

在此处输入图片描述

答案2

您可以\addlinespace使用booktabs

\documentclass[a4paper,10pt]{article}

\usepackage{longtable}
\usepackage{tabularx}

\newcolumntype{L}{>{\raggedleft}p{0.1\textwidth}}
\newcolumntype{R}{p{0.80\textwidth}}

\usepackage{booktabs}
\setlength{\defaultaddspace}{10pt}

\begin{document}

\begin{longtable}{L!{---}R}
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.\\
\addlinespace
12 & asdf asdf asdf asdf asdf.\\
\addlinespace
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.
\end{longtable}

\end{document} 

在此处输入图片描述

答案3

\\[<dimen>表格中的命令告诉 LaTeX,除了支柱的深度之外,当前行至少延伸到<dimen>基线以下。由于您的行延伸深度远远超过 10pt,因此该[10pt]参数不会添加任何内容。

\addlinespace提供的命令,booktabs可以简单调用

\addlinespace[10pt]

而不是全局更改\defaultaddspace是好的。如果没有包,你可以这样做

\noalign{\vspace{10pt}}

行与行之间。

对于不需要换行符的列,我建议使用相对较新的w列说明符,而不是。它需要,它由 会自动调用。在下面的代码中,我明确加载了它。无论如何 都需要它。>{\raggedleft}p{0.1\textwidth}\usepackage{array}tabularx\newcolumntype

\documentclass[a4paper,10pt]{article}

\usepackage{longtable}
\usepackage{array}

\newcolumntype{L}{w{r}{0.1\textwidth}}
\newcolumntype{R}{p{0.80\textwidth}}

\begin{document}

\begin{longtable}{L!{---}R}
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf 
     asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
     asdf asdf asdf asdf asdf asdf asdf.\\
\noalign{\vspace{10pt}}
12 & asdf asdf asdf asdf asdf.\\
\noalign{\vspace{10pt}}
12 & asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf.\\
\end{longtable}

\end{document}

在此处输入图片描述

相关内容