目前,我正在使用 tabularx 表格手动打印首字母缩略词。但我想使用带有词汇表和首字母缩略词的表格样式:\printglossary[type=\acronymtype,style=mystyle]
目前为止的表格:
\begin{tabularx}{\linewidth}{l @{\hspace{1.5em}=\hspace{1em}}X}
\toprule
\multicolumn{1}{l}{\textbf{Abk.}} & \multicolumn{1}{@{}X}{\textbf{Bedeutung}}\\%
\midrule
%
LED & Light-Emitting Diode \\%
VCC & positive Versorgungsspannung \\%
GND & Ground, negative Versorgungsspannung \\[0.3ex]%
\bottomrule%
\end{tabularx}%
相应样式的代码是什么样的?首字母缩略词定义如下:
\newacronym{led}{LED}{Light-Emitting Diode}
\newacronym{vcc}{VCC}{positive Versorgungsspannung}
\newacronym{gnd}{GND}{Ground, negative Versorgungsspannung}
提前致谢
答案1
据我所知,tabularx
由于环境处理其内容的方式,它无法以词汇表样式工作tabularx
。但是,不使用也可以实现相同的效果tabularx
。以下示例需要最新版本glossaries
(撰写本文时为 v4.01):
\documentclass{article}
\usepackage{calc}
\usepackage{booktabs}
\usepackage{tabularx}% (for comparison)
\usepackage[acronym,nomain]{glossaries}
\makeglossaries
\newacronym{led}{LED}{Light-Emitting Diode}
\newacronym{vcc}{VCC}{positive Versorgungsspannung}
\newacronym{gnd}{GND}{Ground, negative Versorgungsspannung}
\newlength\maxlength
\newlength\thislength
\newglossarystyle{mystyle}
{%
\renewenvironment{theglossary}%
{% start of glossary
% Find maximum width of the first column:
\setlength{\maxlength}{0pt}%
\forglsentries[\currentglossary]{\thislabel}%
{%
\settowidth{\thislength}{\glsentryshort{\thislabel}}%
\ifdim\thislength>\maxlength
\setlength{\maxlength}{\thislength}%
\fi
}%
% Now calculate the width of the second column:
\settowidth{\thislength}{\hspace{1.5em}=\hspace{1em}}%
\setlength{\glsdescwidth}{\linewidth-\maxlength-\thislength-2\tabcolsep}%
% Start the tabular environment
\begin{tabular}{l@{\hspace{1.5em}=\hspace{1em}}p{\glsdescwidth}}
\toprule
\multicolumn{1}{l}{\textbf{Abk.}} &
\multicolumn{1}{@{}l}{\textbf{Bedeutung}}\\%
\midrule
}%
{% end of glossary
\bottomrule
\end{tabular}%
}%
% Header has been incorporated into \begin{theglossary}
\renewcommand*{\glossaryheader}{}%
% Don't do anything between letter groups
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glsgroupskip}{}%
% Set display for each the acronym entry
\renewcommand{\glossentry}[2]{%
\glstarget{##1}{\glsentryshort{##1}}% short form
&
\glsentrylong{##1}% long form
\\% end of row
}%
% No sub-entries, so \subglossentry doesn't need redefining
}
\begin{document}
First use: \gls{led}, \gls{vcc}, \gls{gnd}.
Next use: \gls{led}, \gls{vcc}, \gls{gnd}.
\printglossary[type=\acronymtype,style=mystyle]
Compare with:
\noindent
\begin{tabularx}{\linewidth}{l @{\hspace{1.5em}=\hspace{1em}}X}
\toprule
\multicolumn{1}{l}{\textbf{Abk.}} &
\multicolumn{1}{@{}X}{\textbf{Bedeutung}}\\%
\midrule
%
LED & Light-Emitting Diode \\%
VCC & positive Versorgungsspannung \\%
GND & Ground, negative Versorgungsspannung \\[0.3ex]%
\bottomrule%
\end{tabularx}%
\end{document}
得出的结果为:
请注意,缩写词已按字母顺序排列。如果您希望按定义顺序排列,则需要使用sort=def
包选项。