如何在词汇表中添加“页面”或“页数”一词

如何在词汇表中添加“页面”或“页数”一词

我想在词汇表中添加“page”或“pages”一词。以下是代码。词汇表的每个条目末尾都有一个页码。但我希望它显示为:(第 1 页)或(第 1-4 页)或(第 1、2 页)。此外,如何扩大缩写和描述之间的空间?我该如何实现这些?任何帮助都将不胜感激。

    \documentclass[a4paper]{book}
    \usepackage[pagebackref=true,hyperindex=true,hyperfigures=true,pdfduplex=DuplexFlipLongEdge]{hyperref}
    \usepackage{datatool}  
    \usepackage[toc,acronym]{glossaries} 
    \usepackage[xindy]{imakeidx}
    \usepackage{amsmath,amsfonts}
    \makeindex
    \makeglossaries 
    \newglossaryentry{2D}{name=2D,
      description={2 dimensional}}
    \renewcommand*{\glossarypreamble}{%
      \label{\currentglossary}%
    }
    \begin{document} 
    Some text about \gls{2D}.
    \printglossaries
    \end{document} 

答案1

最简单的方法是glossaries-extra

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage[xindy]{glossaries-extra}

\makeglossaries

\GlsXtrEnablePreLocationTag{(page }{(pages }
\renewcommand{\GlsXtrFormatLocationList}[1]{#1)}

\newglossaryentry{2D}{name=2D,
  description={2 dimensional}}

\newglossaryentry{1D}{name=1D,
  description={1 dimensional}}

\newglossaryentry{3D}{name=3D,
  description={3 dimensional}}


\begin{document}
Some text about \gls{2D}.
Some text about \gls{1D}.
Some text about \gls{3D}.
\newpage
Some more text about \gls{2D}.
Some more text about \gls{3D}.
\newpage
Some more text about \gls{3D}.

\printglossaries
\end{document}

词汇表图片

如果只使用基础包的话,情况会稍微复杂一些glossaries

\documentclass[a4paper]{book}
\usepackage[pagebackref=true,hyperindex=true,hyperfigures=true,pdfduplex=DuplexFlipLongEdge]{hyperref}
\usepackage{datatool}
\usepackage[toc,acronym]{glossaries}
\usepackage[xindy]{imakeidx}
\usepackage{amsmath,amsfonts}
\makeindex
\makeglossaries
\newglossaryentry{2D}{name=2D,
  description={2 dimensional}}

\newglossaryentry{1D}{name=1D,
  description={1 dimensional}}

\newglossaryentry{3D}{name=3D,
  description={3 dimensional}}

\renewcommand*{\glossarypreamble}{%
  \label{\currentglossary}%
}

\renewcommand{\glsnumberformat}[1]{%
 (\ifthenelse{\DTLisSubString{#1}{\delimN}\OR\DTLisSubString{#1}{\delimR}}%
  {pages #1}{page #1})}
\begin{document}
Some text about \gls{2D}.
Some text about \gls{1D}.
Some text about \gls{3D}.
\newpage
Some more text about \gls{2D}.
Some more text about \gls{3D}.
\newpage
Some more text about \gls{3D}.

\printglossaries
\end{document}

最终的词汇表如下:

词汇表图片

(您可能想要使用它nopostdot,这样它就不会在描述后插入句号。或者,将“page”/“pages”大写。该glossaries-extra包具有nopostdot默认值。)

为了增加缩写和描述之间的间距,您可以使用不同的样式,例如long,或者您可以定义一种新样式。例如:

\documentclass[a4paper]{book}
\usepackage[pagebackref=true,hyperindex=true,hyperfigures=true,pdfduplex=DuplexFlipLongEdge]{hyperref}
\usepackage{datatool}  
\usepackage[toc,acronym]{glossaries} 
\usepackage[xindy]{imakeidx}
\usepackage{amsmath,amsfonts}
\makeindex
\makeglossaries 
\newglossaryentry{2D}{name=2D,
  description={2 dimensional}}

\newglossaryentry{1D}{name=1D,
  description={1 dimensional}}

\newglossaryentry{3D}{name=3D,
  description={3 dimensional}}

\renewcommand*{\glossarypreamble}{%
  \label{\currentglossary}%
}

\newglossarystyle{mylist}%
{%
  \glossarystyle{list}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \item[\glsentryitem{##1}\glstarget{##1}{##2}]
     \hspace*{1cm}##3\glspostdescription\space ##5}%
}
\glossarystyle{mylist}

\renewcommand{\glsnumberformat}[1]{%
 (\ifthenelse{\DTLisSubString{#1}{\delimN}\OR\DTLisSubString{#1}{\delimR}}%
  {Pages #1}{Page #1})}

\begin{document} 
Some text about \gls{2D}.
Some text about \gls{1D}.
Some text about \gls{3D}.
\newpage
Some more text about \gls{2D}.
Some more text about \gls{3D}.
\newpage
Some more text about \gls{3D}.

\printglossaries
\end{document} 

最终的词汇表如下所示:

词汇表图片

相关内容