4

I want to add grouping headers to the super glossary style of the latex package glossaries, i.e. something analogous to the listgroup style but with the formatting of super. The problem with listgroup is that it adds too much vertical spacing and the descriptions are not aligned. I've also tried alttreegroup but again I'm not entirely happy with the vertical spacing and I don't like the fact that I have to manually change the horizontal spacing with glssetwidest. I'm aware of the post Customising glossary group titles, but unfortunately the newglossarystyle defined there is not quite what I'm looking for. So, how can I get a "supergroup" glossary style? Here is a MWE to work with:

\documentclass{report}

\usepackage{setspace}
\usepackage[nopostdot,nonumberlist,acronyms,section]{glossaries}
\setglossarystyle{super}
%\setglossarystyle{listgroup}
%\setglossarystyle{alttreegroup}
%\glssetwidest{00000}

\newglossary[slg]{symbol}{sot}{stn}{Symbols}
\makeglossaries

\newglossaryentry{area}{
  type=symbol,
  name={\ensuremath{S}},
  description={reference area},
  sort={aS}
}
\newglossaryentry{span}{
  type=symbol,
  name={\ensuremath{b}},
  description={wing span},
  sort={ab}
}
\newglossaryentry{dynp}{
  type=symbol,
  name={\ensuremath{q_\infty}},
  description={dynamic pressure},
  sort={aq}
}
\newglossaryentry{aoa}{
  type=symbol,
  name={\ensuremath{\alpha}},
  description={angle of attack},
  sort={ga}
}
\newacronym
[sort={a}]
{bcr}{BCR}{Block Compressed Row}
\newacronym
[sort={a}]
{cad}{CAD}{Computer-Aided Design}

\newcommand*{\Agroupname}{Alphanumeric}
\newcommand*{\Ggroupname}{Greek letters}


\begin{document}
\onehalfspacing

\section*{List of Symbols and Acronyms}
\glsaddall
\printglossary[type=symbol]
\renewcommand*{\glsgroupheading}[1]{}%
\printglossary[type=acronym]

\end{document}

By the way, is there a better way to rename groups than redefining \Agroupname and \Ggroupname}?

jalalhugo
  • 477

1 Answers1

8

I think for this sort of thing, you might be better off using sub-entries, like this:

\documentclass{report}

\usepackage{setspace}
\usepackage[nopostdot,nonumberlist,acronyms,section]{glossaries}

\newglossarystyle{supergroup}{%
  \setglossarystyle{super}%
  \renewcommand*{\glsgroupskip}{}%
  \renewcommand{\glossentry}[2]{%
    \tabularnewline
    \multicolumn{2}{c}{%
     \bfseries\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}}%
    }% 
    \tabularnewline
    \tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{%
     \glssubentryitem{##2}%
     \glstarget{##2}{\glossentryname{##2}}
     &
     \glossentrydesc{##2}\glspostdescription\space
     ##3\tabularnewline
  }%
}

\newglossary[slg]{symbol}{sot}{stn}{Symbols}
\makeglossaries

\newglossaryentry{alpha}{
  type=symbol,
  name={Alphanumeric},
  description={}}

\newglossaryentry{greek}{
  type=symbol,
  name={Greek letters},
  description={}}

\newglossaryentry{area}{
  type=symbol,
  name={\ensuremath{S}},
  description={reference area},
  sort={S},
  parent=alpha
}
\newglossaryentry{span}{
  type=symbol,
  name={\ensuremath{b}},
  sort={b},
  description={wing span},
  parent=alpha
}
\newglossaryentry{dynp}{
  type=symbol,
  name={\ensuremath{q_\infty}},
  description={dynamic pressure},
  sort={q},
  parent=alpha
}
\newglossaryentry{aoa}{
  type=symbol,
  name={\ensuremath{\alpha}},
  description={angle of attack},
  sort={a},
  parent=greek
}
\newacronym
[sort={a}]
{bcr}{BCR}{Block Compressed Row}
\newacronym
[sort={a}]
{cad}{CAD}{Computer-Aided Design}

\begin{document}
\onehalfspacing

\section*{List of Symbols and Acronyms}
\glsaddall

\printglossary[type=symbol,style=supergroup]
\printglossary[type=acronym]

\end{document}

This produces:

Image of resulting document

Edit:

The justification of the parent entry can be changed by modifying the column alignment in the \multicolumn command. For example, replace

\multicolumn{2}{c}

with

\multicolumn{2}{l}

The vertical spacing above and below the parent entry is a bit more problematic. This spacing is introduced by the first and last \tabularnewline in the definition of \glossentry:

\renewcommand{\glossentry}[2]{%
  \tabularnewline
  \multicolumn{2}{c}{%
   \bfseries\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}}%
  }% 
  \tabularnewline
  \tabularnewline
}%

Unfortunately, you can't simply remove the first \tabularnewline or you'll get a ! Misplaced \omit error. Something is being inserted at the start of the row that interferes with \multicolumn. The simplest solution that I can think of is to insert an extra unused column like this:

\newglossarystyle{supergroup}{%
  \renewenvironment{theglossary}%
  {\tablehead{}\tabletail{}%
   \begin{supertabular}{@{}l@{}lp{\glsdescwidth}}}%
  {\end{supertabular}}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupskip}{}%
  \renewcommand*{\glossentry}[2]{%
    &\multicolumn{2}{@{}l}{%
     \bfseries\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}}%
    }% 
    \tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{%
     &\glssubentryitem{##2}%
     \glstarget{##2}{\glossentryname{##2}}
     &
     \glossentrydesc{##2}\glspostdescription\space
     ##3%
     \tabularnewline
  }%
}

The symbol list now looks like:

Image of symbol list

Nicola Talbot
  • 41,153
  • Thanks! I also added style=super to the acronym glossary. Two more things: 1) how would you left justify the parent entries? 2) how would you reduce the vertical spacing around the parent entries? – jalalhugo Jul 04 '14 at 14:26
  • Yes, changing the c for l did the trick. As for the vertical spacing, it works but unfortunately the symbol glossary is no longer aligned with the acronym glossary. Also, I tried to comment out \renewcommand*{\glsgroupskip}{} to retain some spacing between the two groups but I got an error. Anyway, thank you very much for your help, I think I will stick with your first solution but keep l instead of c in the multicolumn function. – jalalhugo Jul 04 '14 at 15:03
  • @Nicola_Talbot I use your first method to my third index, but now \footcite{} in this glossary entries did not print yet in the footer. An idea ? – Zouib Jul 08 '15 at 16:21
  • @Zouib I think you will have to ask a new question with a MWE containing \footcite. You can link back to this question. – Nicola Talbot Jul 09 '15 at 11:43
  • @NicolaTalbot how can one prevent a page break between the group title and the first entry of the group? – Mace Jul 08 '17 at 14:49
  • @NicolaTalbot, How can I make this style use for per chapter design. I am not able to use it for per chapter, here all glossaries are printed. I want to print only those which are used in that chapter only. Like wise for other chapter. In addition how to modify it so that after first chapter only unique glossaries not used in previous chapter are only printed. – Deb bijan Aug 15 '18 at 16:49