1

I am writing a thesis using the book class and thanks to the glossaries package, I can have a list of symbols grouped in different categories with the alttree style.

Since I am using "option 2", that is using makeindex with \makeglossaries and \printglossaries I had to resort to create different categories (here Greek and Latin) by using \newglossaryentry. I avoid weird vertical spacings by sorting the entries myself and by using the sort=def,nogroupskippackage options.

However, I am not happy with the space between "angular frequency" and the heading "Latin symbols" (in red on the picture) and in a minor proportion of the space between the heading and its first entry (in blue)

Is there an elegant way to add more vertical space for these two locations, without changing the vertical space between entries? I tried to have a look in the manual as well as in the package code which are both verbose, but glossaries is extremely painful to customize compared to others.

too small vertical spacings near heading

MWE:

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[automake,nonumberlist,sort=def,nogroupskip]{glossaries}

\newglossary*{symbols}{List of Symbols}
\makeglossaries

\glssetwidest{X}

\newglossaryentry{greeksymbols} {name={Greek symbols}, description={\nopostdesc}}
\newglossaryentry{latinsymbols} {name={Latin symbols}, description={\nopostdesc}}

\newglossaryentry{s_tau}  {type=symbols, parent=greeksymbols, description={relaxation time},   name={\ensuremath{\tau}}}
\newglossaryentry{s_omega}{type=symbols, parent=greeksymbols, description={angular frequency}, name={\ensuremath{\omega}}}

\newglossaryentry{s_A}    {type=symbols, parent=latinsymbols, description={wave amplitude},    name={\ensuremath{A}}}
\newglossaryentry{s_F}    {type=symbols, parent=latinsymbols, description={reduced frequency}, name={\ensuremath{F}}}

\begin{document}

\printglossary[type=symbols,style=alttree]

\clearpage

Hello world, using \gls{s_tau}, \gls{s_omega}, \gls{s_A} and \gls{s_F}

\end{document}
5
  • 1
    Could be name={\parbox{\textwidth}{\vspace{3mm}Latin symbols\vspace{5mm}}} the answer to your question? (first vspace controls the space above)
    – Venez
    Commented Apr 16, 2020 at 14:16
  • It's dirty but it seems to do the job! Commented Apr 16, 2020 at 18:33
  • well, you could modify an existing style, but because you wrote "is extremely painful to customize" you would prefer a different solution
    – Venez
    Commented Apr 17, 2020 at 8:56
  • why is it necessary to use a \parbox @Venez? Commented Apr 20, 2020 at 15:20
  • Honestly? Because for every other box i tried it did not work ^^ But mbox for example uses only the minimal space the box content requires - and in my experience this does not include e.g. vspace.
    – Venez
    Commented Apr 20, 2020 at 16:01

1 Answer 1

0

Since I had a similar problem I wanted a better generic solution. With this solution you can set arbitrary vertical spaces before and after each entry depending on its layer.

Adaptations

  • I created a new style: glossary-alttreeX.sty
    • It contains an extension of the style alttree
    • It provides a command for setting the vertical spaces for each layer:
      \alttreeXsetLayerVS[<layer>]{<vertical space before>}{<vertical space after}
      
      • The default layer is 0 (the first layer)
  • Use the style and set the spacing:
    \usepackage{glossary-alttreeX}
    \alttreeXsetLayerVS{2ex}{.2ex} % sets vs for layer 0
    \alttreeXsetLayerVS[1]{.8ex}{.2ex}
    
  • Use \glsaddallunused to print all gloassary entries without having to list them and set style=alttreeX:
    \glsaddallunused
    \printglossary[type=symbols,style=alttreeX]
    

Result

enter image description here

Note

Put the glossary-alttreeX.sty into the same directory the tex file or into your local directory (see packages - Where do I place my own .sty or .cls files, to make them available to all my .tex files?).

Code

glossary-alttreeX.sty

% This is file `glossary-alttreeX.sty' by dexteritas (Copyright 2022)
% This file is based on `glossary-tree.sty' by Nicola Talbot (Copyright 2021)
\ProvidesPackage{glossary-alttreeX}[2022/09/02]

\providecommand{\alttreeXsetLayerVS}[3][0]{%
    % [#1] = Layer
    %  #2  = vertical space before
    %  #3  = vertical space after
    \@namedef{@alttreeXvsLayer#1-Before}{#2}
    \@namedef{@alttreeXvsLayer#1-After}{#3}
}

\newglossarystyle{alttreeX}{%
  \renewenvironment{theglossary}%
    {\def\@gls@prevlevel{-1}%
     \mbox{}\par}%
    {\par}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{}%
  \renewcommand{\glossentry}[2]{%
    \ifnum\@gls@prevlevel=0\relax
    \else
       \settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
    \fi
    \hangindent\glstreeindent
    \parindent\glstreeindent
    \ifcsname @alttreeXvsLayer0-Before\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer0-Before}} % NEW
    \fi                                            % NEW
    \makebox[0pt][r]{\glstreenamebox{\glstreeindent}{%
       \glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}%
    \ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
    \glossentrydesc{##1}\glspostdescription \space ##2\par
    \ifcsname @alttreeXvsLayer0-After\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer0-After}} % NEW
    \fi                                           % NEW
    \def\@gls@prevlevel{0}%
  }%
  \renewcommand{\subglossentry}[3]{%
    \ifnum##1=1\relax
      \glssubentryitem{##2}%
    \fi
    \ifnum\@gls@prevlevel=##1\relax
    \else
      \@ifundefined{@glswidestname\romannumeral##1}{%
        \settowidth{\gls@tmplen}{\glstreenamefmt{\@glswidestname\space}}}{%
        \settowidth{\gls@tmplen}{\glstreenamefmt{%
           \csname @glswidestname\romannumeral##1\endcsname\space}}}%
      \ifnum\@gls@prevlevel<##1\relax
         \setlength\glstreeindent\gls@tmplen
         \addtolength\glstreeindent\parindent
         \parindent\glstreeindent
      \else
         \@ifundefined{@glswidestname\romannumeral\@gls@prevlevel}{%
           \settowidth{\glstreeindent}{\glstreenamefmt{%
              \@glswidestname\space}}}{%
           \settowidth{\glstreeindent}{\glstreenamefmt{%
              \csname @glswidestname\romannumeral\@gls@prevlevel
                 \endcsname\space}}}%
         \addtolength\parindent{-\glstreeindent}%
         \setlength\glstreeindent\parindent
      \fi
    \fi
    \hangindent\glstreeindent
    \ifcsname @alttreeXvsLayer##1-Before\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer##1-Before}} % NEW
    \fi                                              % NEW
    \makebox[0pt][r]{\glstreenamebox{\gls@tmplen}{%
      \glstreenamefmt{\glstarget{##2}{\glossentryname{##2}}}}}%
    \ifglshassymbol{##2}{(\glossentrysymbol{##2})\space}{}%
    \glossentrydesc{##2}\glspostdescription\space ##3\par
    \ifcsname @alttreeXvsLayer##1-After\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer##1-After}} % NEW
    \fi                                             % NEW
    \def\@gls@prevlevel{##1}%
  }%
  \renewcommand*{\glsgroupskip}{\ifglsnogroupskip\else\indexspace\fi}%
}

\endinput

example.tex

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[automake,nonumberlist,sort=def,nogroupskip]{glossaries}

\usepackage{glossary-alttreeX}
\alttreeXsetLayerVS{2ex}{.2ex}
\alttreeXsetLayerVS[1]{.8ex}{.2ex}

\newglossary*{symbols}{List of Symbols}
\makeglossaries

\glssetwidest{X}

\newglossaryentry{A} {name={Topic A}, description={\nopostdesc}}
\newglossaryentry{B} {name={Topic B}, description={\nopostdesc}}

\newglossaryentry{greeksymbols} {name={Greek symbols}, description={\nopostdesc}, parent=A}
\newglossaryentry{latinsymbols} {name={Latin symbols}, description={\nopostdesc}, parent=A}

\newglossaryentry{s_tau}  {type=symbols, parent=greeksymbols, description={relaxation time},   name={\ensuremath{\tau}}}
\newglossaryentry{s_omega}{type=symbols, parent=greeksymbols, description={angular frequency}, name={\ensuremath{\omega}}}

\newglossaryentry{s_A}    {type=symbols, parent=latinsymbols, description={wave amplitude},    name={\ensuremath{A}}}
\newglossaryentry{s_F}    {type=symbols, parent=latinsymbols, description={reduced frequency}, name={\ensuremath{F}}}

\newglossaryentry{greeksymbolsB} {name={Greek symbols}, description={\nopostdesc}, parent=B}

\newglossaryentry{s_tauB}  {type=symbols, parent=greeksymbolsB, description={relaxation time},   name={\ensuremath{\tau}}}

\begin{document}

\glsaddallunused
\printglossary[type=symbols,style=alttreeX]

\end{document}

You must log in to answer this question.

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