[Tex/LaTex] group naming with super glossaries style

glossaries

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

Best Answer

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

Related Question