1

I am using the sample code provided by TEX.SX provided by Talbot and also here and here where I have commented for a solution, which is for glossary per chapter. But here the glossaries are not arranged in an aligned mode which looks very bad in formatting. It would be very good if both the name and description etc are aligned vertically so that there is clear readability of each of the glossary terms, symbols, acronym, notation or whatever be the custom glossaries used per chapter. The super style is good looking, but not able to do using the provided idea for per chapter in mentioned link.

The MWE may same as provided in this page or I have copied here another from this page

\documentclass[hidelinks, twoside,11pt]{book}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage{datatool-base}
\usepackage[nomain, counter=chapter,xindy, section=section, acronym, nonumberlist,nopostdot,nogroupskip, toc,symbols,numbers]{glossaries}

\makeglossaries

% load some dummy acronyms for testing
\loadglsentries{example-glossaries-acronym.tex}

\begin{document}
\tableofcontents

\singlespacing
\printglossary[title={List of Abbreviations}]
\doublespacing

\chapter{Sample Text}

\lipsum % dummy text - remove from real document

Add all the acronyms for testing purposes \glsaddall

\end{document} 

The following output format per chapter would be good. Also if added features provided so that if someone doesn't want per chapter but per parts (containing few chapters) or single glossary in a book would cover all aspects. enter image description here

1 Answer 1

1

The conditional code in my previous answer doesn't work in tabular-like environments because it essentially needs:

  \renewcommand*{\glossentry}[2]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
    \doifinlocation
    {%
      \glossentryname{##1} & \glossentrydesc{##1}\tabularnewline
    }%
  }%

within the style definition, which causes an error.

A better method, especially if you want all the lists to have the same offset for the description, is to use the altlist style. This style needs to know the widest name in order to correctly set up the indentation. The glossary-tree package, in which the alttree style is defined, provides \glsfindwidesttoplevelname, which iterates over all defined entries to determine the widest name (for entries that don't have the parent key set).

For example:

\documentclass{report}
\usepackage[counter=chapter,xindy,section=section]{glossaries}
\GlsSetXdyMinRangeLength{0}
\makeglossaries

\loadglsentries{example-glossaries-acronym.tex}% dummy entries

\newglossarystyle{mystyle}%
{%
  \setglossarystyle{alttree}%
  \renewcommand*{\glossaryentrynumbers}[1]{\striprelax##1\endstriprelax}%
  \renewcommand*{\glsXchapterXglsnumberformat}[2]{##2}%
  \renewcommand*{\delimR}{,}%
  \let\orgglossentry\glossentry
  \renewcommand*{\glossentry}[2]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
    \doifinlocation{\orgglossentry{##1}{}}%
  }%
}
\newcommand{\ifinlocation}[3]{%
 \DTLifinlist{#1}{#2}{#3}{}%
}
\def\striprelax\relax#1\endstriprelax{#1}
\setglossarystyle{mystyle}
\glsfindwidesttoplevelname

\begin{document}
\chapter{Sample Chapter}
\printglossary
Test dummy entries: \gls{lid}, \gls{aeu} and \gls{eii}.

\glsresetall 
\chapter{Another Chapter}
\printglossary

Test dummy entries: \gls{pqv}, \gls{aeu} and \gls{eii}.
\end{document}

Page 1:

image of page 1

Page 2:

image of page 2

You might want to switch off the group separator (nogroupskip) if there are only a few entries in each list, and also add some extra vertical spacing after the glossary to separate it from the following text:

\newglossarystyle{mystyle}%
{%
  \setglossarystyle{alttree}%
  \renewenvironment{theglossary}%
  {\csdef{@gls@prevlevel}{-1}\mbox{}\par}%
  {\par\bigskip\par}% extra space after glossary
  \renewcommand*{\glsgroupskip}{}% no group separation
  \renewcommand*{\glossaryentrynumbers}[1]{\striprelax##1\endstriprelax}%
  \renewcommand*{\glsXchapterXglsnumberformat}[2]{##2}%
  \renewcommand*{\delimR}{,}%
  \let\orgglossentry\glossentry
  \renewcommand*{\glossentry}[2]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
    \doifinlocation{\orgglossentry{##1}{}}%
  }%
}

Alternatively, instead of using \glsfindwidesttoplevelname you can explicitly set the widest name using \glssetwidest, so if you want a bit more space you could do:

\documentclass{report}
\usepackage[counter=chapter,xindy,section=section]{glossaries}
\GlsSetXdyMinRangeLength{0}
\makeglossaries

\loadglsentries{example-glossaries-acronym.tex}% dummy entries

\newglossarystyle{mystyle}%
{%
  \setglossarystyle{alttree}%
  \renewenvironment{theglossary}%
  {\csdef{@gls@prevlevel}{-1}\mbox{}\par}%
  {\par\bigskip\par}% extra space after glossary
  \renewcommand*{\glsgroupskip}{}% no group separation
  \renewcommand*{\glossaryentrynumbers}[1]{\striprelax##1\endstriprelax}%
  \renewcommand*{\glsXchapterXglsnumberformat}[2]{##2}%
  \renewcommand*{\delimR}{,}%
  \let\orgglossentry\glossentry
  \renewcommand*{\glossentry}[2]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
    \doifinlocation{\orgglossentry{##1}{}}%
  }%
}
\newcommand{\ifinlocation}[3]{%
 \DTLifinlist{#1}{#2}{#3}{}%
}
\def\striprelax\relax#1\endstriprelax{#1}
\setglossarystyle{mystyle}

\glssetwidest{xxxxxxxxxx}

\begin{document}
\chapter{Sample Chapter}
\printglossary
Test dummy entries: \gls{lid}, \gls{aeu} and \gls{eii}.

\glsresetall 
\chapter{Another Chapter}
\printglossary

Test dummy entries: \gls{pqv}, \gls{aeu} and \gls{eii}.
\end{document}

image of page 1

The heading can be adjusted by redefining \glossarysection. For example (requires xcolor package):

\renewcommand{\glossarysection}[2][]{%
 \par\noindent
 \colorbox{lightgray}{\parbox{\linewidth}{\centering\MakeTextUppercase{#2}}}%
 \par
}

The title can be changed with the title key in the optional argument of \printglossary. For example:

\printglossary[title={List of Key Terms}]
2
  • @Talbot thanks for your time, its good and working for me now. But here only unique glossaries are printed per chapter. But I need to reset it for every chapter. I have tried with and without both glsresetall but every time only unique glossaries are printed. How can I use the above code to work for resetting every chapter so that all used in current chapter are printed irrespective of used in earlier chapter.Just out of curiosity asking, How can I change the font color and style for glossary name and description if sometimes say I need to print them in red color for description.
    – Deb bijan
    Sep 8, 2018 at 9:43
  • for my previous query, I like to mention that I am using following in preamble \usepackage[nomain,counter=chapter,xindy, section=section, acronym, nonumberlist,nopostdot,nogroupskip,symbols,numbers]{glossaries} \usepackage{glossaries-extra} \usepackage{glossary-inline} \usepackage{glossary-mcols} \usepackage{glossary-longragged} \usepackage{glossary-superragged} \usepackage{glossary-longbooktabs} These all I have used for using with glossaries. Are these Ok? Should any of them to be modifed so that glsresetall works.
    – Deb bijan
    Sep 8, 2018 at 17:53

You must log in to answer this question.

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