\newglossarystyle 对词汇表中的条目进行错误分组

\newglossarystyle 对词汇表中的条目进行错误分组

glossaries我正在尝试使用该包来布局词汇表。我正在使用index样式,并尝试在首字母缩略词后添加冒号。

\documentclass{article}
\usepackage[acronyms,nomain]{glossaries}

\makeglossaries
\newacronym{ABC}{ABC}{Alpha Bravo Charlie}
\newacronym{NASA}{NASA}{National Aeronautics and Space Administration}
\newacronym{NSA}{NSA}{National Security Agency}
\newacronym{NATO}{NATO}{North Atlantic Treaty Organization}
\newacronym{EU}{EU}{European Union}
\newacronym{ECDC}{ECDC}{European Centre for Disease Prevention and Control}
\newacronym{EWRS}{EWRS}{Early Warning and Response System}
\newacronym{USA}{USA}{United States of America}

\begin{document}

\gls{ABC}
\gls{NASA}
\gls{NSA}
\gls{NATO}
\gls{EU}
\gls{ECDC}
\gls{EWRS}
\gls{USA}

\setglossarystyle{index}
\renewcommand*{\glsgroupskip}{\vspace{8pt}}
\printglossary[type=\acronymtype,title=Glossary]

\newglossarystyle{mystyle}{%
    \setglossarystyle{index}%
    \renewcommand*{\glsgroupskip}{\vspace{8pt}}%
    \renewcommand*{\glossentry}[2]{%
        \textbf{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}:}}
        \glossentrydesc{##1}\glspostdescription\space ##2\\
    }%
}
\setglossarystyle{mystyle}
\printglossary[type=\acronymtype,title=Glossary]

\end{document}

请注意,第一个词汇表仅使用index样式,可以正确地按字母顺序对项目进行分组。但是,当我使用自己的样式(在条目名称后附加冒号)时,分组突然变得不正确。我做错了什么?

答案1

使用\par而不是似乎\\给出了期望的结果,但是真正的问题似乎是您偏离了样式中的定义\glossentry太远,它使用了一个列表并且期望。\glossentryindex\item

而是修改样式\glossentry中的定义index以插入冒号

\renewcommand*{\glossentry}[2]{%
    \item\glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}%
    \ifglshassymbol{##1}{\space(\glossentrysymbol{##1})}{}%
    \glstreenamefmt{:}%  <== This line added
    \glstreepredesc \glossentrydesc{##1}\glspostdescription\space ##2%
}%

看起来更像你想要的。

编译代码

\documentclass{article}
\usepackage[acronyms,nomain]{glossaries}

\makeglossaries
\newacronym{ABC}{ABC}{Alpha Bravo Charlie}
\newacronym{NASA}{NASA}{National Aeronautics and Space Administration}
\newacronym{NSA}{NSA}{National Security Agency}
\newacronym{NATO}{NATO}{North Atlantic Treaty Organization}
\newacronym{EU}{EU}{European Union}
\newacronym{ECDC}{ECDC}{European Centre for Disease Prevention and Control}
\newacronym{EWRS}{EWRS}{Early Warning and Response System}
\newacronym{USA}{USA}{United States of America}

\begin{document}

\gls{ABC}
\gls{NASA}
\gls{NSA}
\gls{NATO}
\gls{EU}
\gls{ECDC}
\gls{EWRS}
\gls{USA}

\setglossarystyle{index}
\renewcommand*{\glsgroupskip}{\vspace{8pt}}
\printglossary[type=\acronymtype,title=Glossary]

\newglossarystyle{mystyle}{%
    \setglossarystyle{index}%
    \renewcommand*{\glsgroupskip}{\vspace{8pt}}%
    \renewcommand*{\glossentry}[2]{%
        \item\glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}%
        \glstreenamefmt{:}%
        \ifglshassymbol{##1}{\space(\glossentrysymbol{##1})}{}%
        \glstreepredesc \glossentrydesc{##1}\glspostdescription\space ##2%
    }%
}
\setglossarystyle{mystyle}
\printglossary[type=\acronymtype,title=Glossary]

\end{document}

相关内容