8

I would like to add the word "page" or "pages" in the Glossary. The following is the code. At the end of each entry for Glossary, there is a page number. But I would like it to display like: (page 1), or (pages 1-4), or (pages 1, 2). Also, how to enlarge the space between the abbreviation and description? How can I achieve these? Any help will be appreciated.

    \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 Answer 1

5

The simplest approach is with 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}

image of glossary

It's a bit more complicated with just the base glossaries package:

\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}

The resulting glossary looks like:

Image of glossary

(You might want to use nopostdot so it doesn't insert a full stop after the description. Alternatively, capitalise "page"/"pages". The glossaries-extra package has nopostdot as the default.)

To increase the space between the abbreviation and description, you could just use a different style, such as long, or you can define a new style. For example:

\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} 

The resulting glossary now looks like:

Image of glossary

2
  • I would like to do the same but using xindy option of glossaries and keeping the hyperref link actives on the pages numbers. Is there a way to do this ?
    – R. N
    Nov 7, 2014 at 14:54
  • Thank you for this great answer! Can someone please mark it as the correct answer? @jingfen-chen ? Jun 13, 2018 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .