![如何在词汇表包中使用 xltabular 环境?](https://linux22.com/image/412065/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%AF%8D%E6%B1%87%E8%A1%A8%E5%8C%85%E4%B8%AD%E4%BD%BF%E7%94%A8%20xltabular%20%E7%8E%AF%E5%A2%83%EF%BC%9F.png)
我使用 MWE 中的环境定义了 glossarystyle longtable
:
\documentclass{article}
\usepackage[nopostdot,nonumberlist,acronym]{glossaries-extra}
\renewcommand{\newacronym}[3]{%
\newglossaryentry{#1}{%
type=acronym,
name=#2,
description={#3},
first={{#3} ({#2})},
}
}
\newglossarystyle{acronym}
{%
\setglossarystyle{long}
\renewenvironment{theglossary}%
{\begin{longtable}[l]{p{0.13\textwidth}p{0.05\textwidth}p{0.82\textwidth}}}%
{\end{longtable}}
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
— & \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
}%
}
\newacronym{PNG}{PNG} {Portable Network Graphics }
\newacronym{SVG}{SVG} {Scalable Vector Graphics}
\newacronym{JPEG}{JPEG} {Joint Photographic Experts Group}
\makeglossaries
\begin{document}
\glsaddall
\printglossary[type=acronym,style=acronym,title={}]
First use of \gls{JPEG} and \gls{PNG}. Second use of \gls{PNG} and \gls{JPEG}.
\end{document}
而且效果很好。有一天,我决定将其更改longtable
为xltabular
,如下所示:
\documentclass{article}
\usepackage[nopostdot,nonumberlist,acronym]{glossaries-extra}
\usepackage{xltabular}
\renewcommand{\newacronym}[3]{%
\newglossaryentry{#1}{%
type=acronym,
name=#2,
description={#3},
first={{#3} ({#2})},
}
}
\newglossarystyle{acronym}
{%
\setglossarystyle{long}
\renewenvironment{theglossary}%
{\begin{xltabular}{\textwidth}{|l|c|X|}}%
{\end{xltabular}}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
— & \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
}%
}
\newacronym{PNG}{PNG} {Portable Network Graphics }
\newacronym{SVG}{SVG} {Scalable Vector Graphics}
\newacronym{JPEG}{JPEG} {Joint Photographic Experts Group}
\makeglossaries
\begin{document}
\glsaddall
\printglossary[type=acronym,style=acronym,title={}]
First use of \gls{JPEG} and \gls{PNG}. Second use of \gls{PNG} and \gls{JPEG}.
\end{document}
我遇到了一些错误:
File ended while scanning use of \TX@get@body. ...lossary[type=acronym,style=acronym,title={}]
\begin{xltabular} on input line 2 ended by \end{document}. \end{document}
longtable
我认为,错误是由和中的非可选参数数量不同引起的xltabular
,但无法找到解决此问题的线索。
答案1
如果您有一个表格/词汇表需要跨越多个页面,并且希望能够通过X
在表格中使用来动态调整列宽,那么xltabular
这是一个非常好的选择。它也为我解决了这个问题!
遗憾的是,无法在新环境定义中使用\begin{xltabular}
和。不过,您可以使用和。\end{xltabular}
\xltabular{\linewidth}{...}
\endxltabular
这是一个具有可变列宽的三列词汇表样式:
% --------------------------------------------------------------------------------
% Style of the Symbols List
% --------------------------------------------------------------------------------
\newglossarystyle{symbstyle} {
\setglossarystyle{long3col} % base this style on the list style
\renewenvironment{theglossary} {
% Change the table type --> 3 columns
\xltabular{\linewidth}{p{0.2\textwidth}Xp{0.1\textwidth}}
}{
\endxltabular
}
% Change the table header / footer
\renewcommand*{\glossaryheader} {
\bfseries Head1 & \bfseries Head2 & \bfseries Head3 \\
\hline \endfirsthead
\hline \endfoot
}
% Change the displayed items
\renewcommand*{\glossentry}[2] {
\glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1} & \glspostdescription{##1} \\
% Head1 Head2 Head3
}
}
希望这能帮助到别人!
答案2
谢谢这个答案我找到解决办法了。
\documentclass{article}
\usepackage[nopostdot,nonumberlist,acronym]{glossaries-extra}
\usepackage{xltabular}
\usepackage{environ} % Used to define custom table environment
\renewcommand{\newacronym}[3]{%
\newglossaryentry{#1}{%
type=acronym,
name=#2,
description={#3},
first={{#3} ({#2})},
}
}
\NewEnviron{doctable}{%
\begin{xltabular}{\textwidth}{lcX}%
\BODY
\end{xltabular}
}
\newglossarystyle{acronym}
{%
\setglossarystyle{long}
\renewenvironment{theglossary}
{%
\doctable
}{
\enddoctable
}
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
— & \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
}%
}
\newacronym{PNG}{PNG} {Portable Network Graphics }
\newacronym{SVG}{SVG} {Scalable Vector Graphics}
\newacronym{JPEG}{JPEG} {Joint Photographic Experts Group}
\makeglossaries
\begin{document}
\glsaddall
\printglossary[type=acronym,style=acronym,title={}]
First use of \gls{JPEG} and \gls{PNG}. Second use of \gls{PNG} and \gls{JPEG}.
\end{document}