长书页样式的词汇表在小页面中没有底线

长书页样式的词汇表在小页面中没有底线

我想将longbooktabs词汇表放入小页面环境中,但当我这样做时,奇怪的是它会丢失bottomrule。我能做些什么呢?

正如 Nicola Talbot 所评论的那样,只需将其放入longtable小页面环境中即可重现该问题,请参阅下面较短的 MWE。

示例 mwe 输出

原始 MWE

别忘了跑步makeglossaries

\documentclass{scrartcl}
\usepackage{glossaries}
\usepackage{glossary-longbooktabs}
\makeglossaries
\newglossaryentry{ex}{name={sample},description={an example}}
\begin{document}
A \gls{ex} glossary with \texttt{style=long-booktabs} has a \texttt{bottomrule}:

\printglossary[style=long-booktabs]

But if put in a minipage, the \texttt{bottomrule} vanishes:

\begin{minipage}{\linewidth}
\printglossary[style=long-booktabs]
\end{minipage}
\end{document}

短 MWE

\documentclass{article}
\usepackage{longtable,booktabs}
\begin{document}
\begin{minipage}{\linewidth}
  \begin{longtable}{l}
    \toprule
    Col\\
    \midrule\endhead
    \bottomrule\endfoot
    A\\
  \end{longtable}
\end{minipage}
\end{document}

答案1

longtable环境设计为跨多个页面,但 的内容minipage不能被破坏,这会造成干扰。由于minipage不能跨多个页面,因此最好使用tabular而不是longtable在它里面。(我假设你只有一个可以放在一页上的简短词汇表。)

你可以定义自己的风格,其工作原理类似于longtable但使用方式tabular如下:

\documentclass{scrartcl}
\usepackage{glossaries}
\usepackage{glossary-longbooktabs}

\newglossarystyle{tabular}{%
  \renewenvironment{theglossary}%
     {\begin{tabular}{lp{\glsdescwidth}}}%
     {\bottomrule\end{tabular}}%
  \renewcommand*{\glossaryheader}{%
    \toprule \bfseries \entryname & \bfseries
  \descriptionname\tabularnewline\midrule}%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{%
     &
     \glssubentryitem{##2}%
     \glstarget{##2}{\strut}\glossentrydesc{##2}\glspostdescription\space
     ##3\tabularnewline
  }%
  \ifglsnogroupskip
    \renewcommand*{\glsgroupskip}{}%
  \else
    \renewcommand*{\glsgroupskip}{\glspenaltygroupskip}%
  \fi
}

\makeglossaries
\newglossaryentry{ex}{name={sample},description={an example}}

\begin{document}
A \gls{ex} glossary with \texttt{style=long-booktabs} has a \texttt{bottomrule}:

\printglossary[style=long-booktabs]

In a minipage using \texttt{tabular} instead of \texttt{longtable}:

\noindent
\begin{minipage}{\linewidth}
\printglossary[style=tabular]
\end{minipage}
\end{document}

词汇表图片

long另一种方法是使用中定义的补充样式之一glossary-longextra,该样式随包提供glossaries-extra。您可以改用使用tabular而不是longtable使用:

\GlsLongExtraUseTabulartrue

在设置样式之前。样式long-name-desc与样式类似long-booktabs,但不包含位置列表。您的示例包括它,但如果您的实际文档有,nonumberlist那么这可能是一个方便的选项:

\documentclass{scrartcl}
\usepackage[postdot]{glossaries-extra}
\usepackage{glossary-longextra}

\makeglossaries
\newglossaryentry{ex}{name={sample},description={an example}}

\begin{document}
A \gls{ex} glossary with \texttt{style=long-booktabs} has a \texttt{bottomrule}:

\printglossary[style=long-booktabs]

In a minipage using \texttt{tabular} instead of \texttt{longtable}:

\noindent
\begin{minipage}{\linewidth}
\GlsLongExtraUseTabulartrue % use before style is set
\printglossary[style=long-name-desc]
\end{minipage}
\end{document}

样本词汇表的图片

这些glossary-longextra样式旨在填充页面宽度。如果您不想要这样,您可以重新定义\glslongextraSetDescWidth不执行任何操作:

\documentclass{scrartcl}
\usepackage[postdot]{glossaries-extra}
\usepackage{glossary-longextra}

\makeglossaries
\newglossaryentry{ex}{name={sample},description={an example}}

\begin{document}
A \gls{ex} glossary with \texttt{style=long-booktabs} has a \texttt{bottomrule}:

\printglossary[style=long-booktabs]

In a minipage using \texttt{tabular} instead of \texttt{longtable}:

\noindent
\begin{minipage}{\linewidth}
\GlsLongExtraUseTabulartrue % use before style is set
\renewcommand{\glslongextraSetDescWidth}{}% don't adjust \glsdescwidth
\printglossary[style=long-name-desc]
\end{minipage}
\end{document}

词汇表图片

相关内容