我怎样才能防止 longtable 出现双重 hrule?

我怎样才能防止 longtable 出现双重 hrule?

我正在从事的一个项目涉及一个通过一些宏生成的词汇表,并使用进行排版。现在,词汇表的每个部分都用来自包的longtable分隔开。现在,这已经足够好了,看起来也不错,但有一个问题:当词汇表部分与页面同时结束时,最终会出现双重规则, 后跟。显然,这看起来不太好。这是我目前正在使用的代码:\midrulebooktabs\midrule\bottomrule

\documentclass{article}
\usepackage{longtable,array,hyperref,multirow,booktabs,fullpage}

\newcommand{\GlossarySection}[2]{%
\multirow{1}{*}{\LARGE\bfseries #1} & foo  & n & lorem ipsum dolor sit &
\multirow{1}{*}{\LARGE\bfseries #2} & foo  & n & consectetur adipiscing elit \\*
& bar  & v & Maecenas sed purus       & & bar  & v & at ipsum placerat luctus \\*
& baz  & p & Nullam luctus id tellus  & & baz  & p & Ut ac ultricies neque \\*
& qux  & v & Aenean consequat commodo & & qux  & v & in sodales metus ultrices \\*
& buux & n & Phasellus tincidunt      & & quux & n & vitae pulvinar nisi mollis \\
\midrule}

\begin{document}\begin{center}
\begin{longtable}{c>{\bfseries}l>{\itshape}c<{.}lc>{\bfseries}l>{\itshape}c<{.}l}
\caption{My Glossary}\label{tab:gloss} \\

\toprule
\endfirsthead

\multicolumn{8}{l}{%
\emph{\small\tablename\ \thetable{}: \nameref{tab:gloss}
--- continued from previous page}} \\
\toprule
\endhead

\bottomrule \multicolumn{8}{r}{\emph{\small Continued on next page}} \\
\endfoot

\bottomrule
\endlastfoot

\GlossarySection{A}{B}
\GlossarySection{C}{D}
\GlossarySection{E}{F}
\GlossarySection{G}{H}
\GlossarySection{I}{J}
\GlossarySection{L}{M}
\GlossarySection{N}{O}
\GlossarySection{P}{Q}
\GlossarySection{R}{S}
\GlossarySection{T}{U}
\GlossarySection{V}{W}
\GlossarySection{Y}{Z}

\end{longtable}\end{center}\end{document}

在此处输入图片描述

从屏幕截图中可以看出,双重规则看起来不太理想。现在一个显而易见的解决方案就是\midrule在分页符处省略。这样做有几个问题:首先,我的项目代码使用宏生成每个部分(与我在此处包含的虚构示例类似)。其次,也许更重要的是,在哪里分页符的出现并不总是可以预测的,并且可能会在编辑内容时发生变化。理想的做法是,仅在分页\midrule符不与页脚相邻时才有条件地插入分页符。

答案1

嗯,例如您可以\bottomrule在头部定义中注释这两个命令。

正如@Mico 在他的评论中提到的:

环境longtable默认水平居中——无需将其包裹在center环境中。

请参阅以下 MWE(更改的代码标有<================):

\documentclass{article}
\usepackage{longtable,array,multirow,booktabs,fullpage,hyperref}

\newcommand{\GlossarySection}[2]{%
\multirow{1}{*}{\LARGE\bfseries #1} & foo  & n & lorem ipsum dolor sit &
\multirow{1}{*}{\LARGE\bfseries #2} & foo  & n & consectetur adipiscing elit \\*
& bar  & v & Maecenas sed purus       & & bar  & v & at ipsum placerat luctus \\*
& baz  & p & Nullam luctus id tellus  & & baz  & p & Ut ac ultricies neque \\*
& qux  & v & Aenean consequat commodo & & qux  & v & in sodales metus ultrices \\*
& buux & n & Phasellus tincidunt      & & quux & n & vitae pulvinar nisi mollis \\
\midrule%
}

\begin{document}
\begin{longtable}{c>{\bfseries}l>{\itshape}c<{.}lc>{\bfseries}l>{\itshape}c<{.}l}
\caption{My Glossary}\label{tab:gloss} \\

\toprule
\endfirsthead

\multicolumn{8}{l}{%
\emph{\small\tablename\ \thetable{}: \nameref{tab:gloss}
--- continued from previous page}} \\
\toprule
\endhead

%\bottomrule % <========================================================
\multicolumn{8}{r}{\emph{\small Continued on next page}} \\
\endfoot

%\bottomrule % <========================================================
\endlastfoot

\GlossarySection{A}{B}
\GlossarySection{C}{D}
\GlossarySection{E}{F}
\GlossarySection{G}{H}
\GlossarySection{I}{J}
\GlossarySection{L}{M}
\GlossarySection{N}{O}
\GlossarySection{P}{Q}
\GlossarySection{R}{S}
\GlossarySection{T}{U}
\GlossarySection{V}{W}
\GlossarySection{Y}{Z}

\end{longtable}

\end{document}

结果如下:

在此处输入图片描述

更新:

一个版本使用颜色代替\midrule。使用命令,\rowcolor{gray!30!white}您将在表格中看到下一行带有浅灰色背景(请参阅xcolor带有的软件包的文档texdoc xcolor)。看到我xcolor使用选项加载了软件包table

以下 MWE:

\documentclass{article}

\usepackage{longtable,array,multirow,booktabs}
\usepackage[table]{xcolor} % <==========================================
\usepackage{hyperref} % <===============================================

\newcommand{\GlossarySection}[2]{%
\multirow{1}{*}{\LARGE\bfseries #1} & foo  & n & lorem ipsum dolor sit &
\multirow{1}{*}{\LARGE\bfseries #2} & foo  & n & consectetur adipiscing elit \\*
& bar  & v & Maecenas sed purus       & & bar  & v & at ipsum placerat luctus \\*
& baz  & p & Nullam luctus id tellus  & & baz  & p & Ut ac ultricies neque \\*
& qux  & v & Aenean consequat commodo & & qux  & v & in sodales metus ultrices \\*
\rowcolor{gray!30!white} % <============================================
& buux & n & Phasellus tincidunt      & & quux & n & vitae pulvinar nisi mollis \\
%\midrule% <============================================================
}


\begin{document}

\begin{longtable}{c>{\bfseries}l>{\itshape}c<{.}lc>{\bfseries}l>{\itshape}c<{.}l}
\caption{My Glossary}\label{tab:gloss} \\

\toprule
\endfirsthead

\multicolumn{8}{l}{%
\emph{\small\tablename\ \thetable{}: \nameref{tab:gloss}
--- continued from previous page}} \\
\toprule
\endhead

\bottomrule % <========================================================
\multicolumn{8}{r}{\emph{\small Continued on next page}} \\
\endfoot

\bottomrule % <========================================================
\endlastfoot

\GlossarySection{A}{B}
\GlossarySection{C}{D}
\GlossarySection{E}{F}
\GlossarySection{G}{H}
\GlossarySection{I}{J}
\GlossarySection{L}{M}
\GlossarySection{N}{O}
\GlossarySection{P}{Q}
\GlossarySection{R}{S}
\GlossarySection{T}{U}
\GlossarySection{V}{W}
\GlossarySection{Y}{Z}

\end{longtable}

\end{document}

给出结果(最后一行和\bottomrule每页末尾都有彩色):

在此处输入图片描述

相关内容