[Tex/LaTex] Glossaries: printglossary on different toc levels

glossariesliststable of contents

I want to create different glossaries chapters for a larger document:

  • Glossary
  • List of acronyms
  • List of symbols

So far, so good. I got that working if I have only one big list of symbols.

My problem arises when using multiple lists of symbols in different sublists, e.g. for scalars, vectors, matrices,… . I created a seperate list for each sublist. In result I want to have one chapter toc entry List of Symbols and one section for each sublist. However, with section=chapter option for \usepackage{glossaries} each sublist is printed as a seperate chapter. This is fine for the glossary and the acronyms, but not for the sublists of symbols.

Is there a way to define the section level seperately for each \printglossary[<options>] command instead of globally in \usepackage[<options>]{glossaries}? Or is there another workaround? I already tried modifying \glossarysection in the glossary style mysymbolstyle but was not able to change the parent toc level.


MWE

Save as doc.tex

\documentclass[a4paper,10pt]{scrreprt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{siunitx}
\usepackage{tabu}

\usepackage[
  acronym,
  toc,
  section=chapter,% chapter|section
]{glossaries}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Redefine package options         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\glspostdescription}{\dotfill}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own styles                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% -----------------
% Acronym-styles
% -----------------

\newglossarystyle{myacronymstyle}{%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {lX}}%
    {\end{longtabu}}%
  % Header line
  \renewcommand*{\glossaryheader}{}%
  % indicate what to do at the start of each logical group
  \renewcommand*{\glsgroupskip}{\tabularnewline}% What to do between groups
  \renewcommand*{\glossaryentryfield}[5]{%
    \glsentryitem{##1}\glstarget{##1}{##2}
    & ##3\glspostdescription ##5% Description
    \\% end of row
  }
}

% -----------------
% Symbols-styles
% -----------------

\newglossarystyle{mysymbolstyle}{%
  %\renewcommand{\glossarysection}[2][]{}% no title
  \renewcommand*{\glsclearpage}{}% avoid page break before glossary
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {clXc}}%
    {\end{longtabu}}%
  % Header line
  \renewcommand*{\glossaryheader}{%
    % Requires booktabs
    %\toprule%
    \textbf{Symbol} & \textbf{Name} & \textbf{Description} & \textbf{Unit}%
    \tabularnewline%
    \tabularnewline%
    %\midrule%
    \endhead%
    %\bottomrule%
    \endfoot%
  }%
  % indicate what to do at the start of each logical group
  \renewcommand*{\glsgroupskip}{\tabularnewline}% What to do between groups
  \renewcommand*{\glossentry}[1]{%
    \glsentryitem{##1}% Entry number if required
    \glstarget{##1}{\glossentrysymbol{##1}} &
    %\glossentrysymbol{##1} & % Symbol
    \glossentryname{##1}    & % Name
    \glossentrydesc{##1}    & % Description
    \glsentryuseri{##1}%      % Unit in User1-Variable
    \tabularnewline%
  }%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own glossaries                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossary[slg1]{onelist}{syi1}{syg1}{Category 1 units}
\newglossary[slg2]{twolist}{syi2}{syg2}{Category 2 units}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%------------------
% Category 1
%------------------

\newglossaryentry{symb:length}{%
  symbol      ={$l$},%
  name        ={Length},%
  description ={Length Description},%
  user1       ={\ensuremath{\protect\si{\protect\metre}}},%
  type        =onelist,%
  sort        =length,%
}

\newglossaryentry{symb:width}{%
  symbol      ={$w$},%
  name        ={Width},%
  description ={Width Description},%
  user1       ={\ensuremath{\protect\si{\protect\metre}}},%
  type        =onelist,%
  sort        =length,%
}

%------------------
% Category 2
%------------------

\newglossaryentry{symb:tmat}{%
  symbol      ={$\mathbf{T}$},%
  name        ={Test},%
  description ={Test description},%
  user1       ={$1$},%
  type        =twolist,%
  sort        =test,%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Acronyms                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newacronym{XYZ}{XYZ}{Explanation of XYZ abbreviation\protect\glsadd{gls:XYZ}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Glossary                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossaryentry{gls:XYZ}{
  name=Name of XYZ,
  description={%
    Description of XYZ
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make glossaries                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeglossaries

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\chapter{Chapter 1}

\lipsum[1-3]

\chapter{Chapter 2}

\lipsum[4-5]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Glossaries                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\glsaddall

\printglossary[style=altlist,title=Glossary]
\printglossary[type=\acronymtype,style=myacronymstyle]

%Symbole ausgeben
\chapter*{List of symbols}
\addcontentsline{toc}{chapter}{List of symbols}
\printglossary[type=onelist,style=mysymbolstyle,nonumberlist,title=test 1]
\printglossary[type=twolist,style=mysymbolstyle,nonumberlist,title=test 2]

\end{document}

Compilation

pdflatex doc.tex
makeindex -s doc.ist -t doc.alg -o doc.acr doc.acn
makeindex -s doc.ist -t doc.glg -o doc.gls doc.glo
makeindex -s doc.ist -t doc.slg1 -o doc.syi1 doc.syg1
makeindex -s doc.ist -t doc.slg2 -o doc.syi2 doc.syg2
pdflatex doc.tex
pdflatex doc.tex

Best Answer

You can change the level inside the document by \setglossarysection{section}:

\printglossary[style=altlist,title=Glossary]
\printglossary[type=\acronymtype,style=myacronymstyle]

%Symbole ausgeben
\chapter*{List of symbols}
\addcontentsline{toc}{chapter}{List of symbols}
\setglossarysection{section}% <- added
\printglossary[type=onelist,style=mysymbolstyle,nonumberlist,title=test 1]
\printglossary[type=twolist,style=mysymbolstyle,nonumberlist,title=test 2]

enter image description here

Code:

\documentclass[a4paper,10pt]{scrreprt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{siunitx}
\usepackage{tabu}

\usepackage[
  acronym,
  toc,
  section=chapter,% chapter|section
]{glossaries}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Redefine package options         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\glspostdescription}{\dotfill}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own styles                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% -----------------
% Acronym-styles
% -----------------

\newglossarystyle{myacronymstyle}{%
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {lX}}%
    {\end{longtabu}}%
  % Header line
  \renewcommand*{\glossaryheader}{}%
  % indicate what to do at the start of each logical group
  \renewcommand*{\glsgroupskip}{\tabularnewline}% What to do between groups
  \renewcommand*{\glossaryentryfield}[5]{%
    \glsentryitem{##1}\glstarget{##1}{##2}
    & ##3\glspostdescription ##5% Description
    \\% end of row
  }
}

% -----------------
% Symbols-styles
% -----------------

\newglossarystyle{mysymbolstyle}{%
  %\renewcommand{\glossarysection}[2][]{}% no title
  \renewcommand*{\glsclearpage}{}% avoid page break before glossary
  \renewenvironment{theglossary}%
    {\begin{longtabu} to \linewidth {clXc}}%
    {\end{longtabu}}%
  % Header line
  \renewcommand*{\glossaryheader}{%
    % Requires booktabs
    %\toprule%
    \textbf{Symbol} & \textbf{Name} & \textbf{Description} & \textbf{Unit}%
    \tabularnewline%
    \tabularnewline%
    %\midrule%
    \endhead%
    %\bottomrule%
    \endfoot%
  }%
  % indicate what to do at the start of each logical group
  \renewcommand*{\glsgroupskip}{\tabularnewline}% What to do between groups
  \renewcommand*{\glossentry}[1]{%
    \glsentryitem{##1}% Entry number if required
    \glstarget{##1}{\glossentrysymbol{##1}} &
    %\glossentrysymbol{##1} & % Symbol
    \glossentryname{##1}    & % Name
    \glossentrydesc{##1}    & % Description
    \glsentryuseri{##1}%      % Unit in User1-Variable
    \tabularnewline%
  }%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Own glossaries                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossary[slg1]{onelist}{syi1}{syg1}{Category 1 units}
\newglossary[slg2]{twolist}{syi2}{syg2}{Category 2 units}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Symbols                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%------------------
% Category 1
%------------------

\newglossaryentry{symb:length}{%
  symbol      ={$l$},%
  name        ={Length},%
  description ={Length Description},%
  user1       ={\ensuremath{\protect\si{\protect\metre}}},%
  type        =onelist,%
  sort        =length,%
}

\newglossaryentry{symb:width}{%
  symbol      ={$w$},%
  name        ={Width},%
  description ={Width Description},%
  user1       ={\ensuremath{\protect\si{\protect\metre}}},%
  type        =onelist,%
  sort        =length,%
}

%------------------
% Category 2
%------------------

\newglossaryentry{symb:tmat}{%
  symbol      ={$\mathbf{T}$},%
  name        ={Test},%
  description ={Test description},%
  user1       ={$1$},%
  type        =twolist,%
  sort        =test,%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Acronyms                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newacronym{XYZ}{XYZ}{Explanation of XYZ abbreviation\protect\glsadd{gls:XYZ}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Glossary                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newglossaryentry{gls:XYZ}{
  name=Name of XYZ,
  description={%
    Description of XYZ
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make glossaries                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeglossaries

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\chapter{Chapter 1}

\lipsum[1-3]

\chapter{Chapter 2}

\lipsum[4-5]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Glossaries                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\glsaddall

\printglossary[style=altlist,title=Glossary]
\printglossary[type=\acronymtype,style=myacronymstyle]

%Symbole ausgeben
\chapter*{List of symbols}
\addcontentsline{toc}{chapter}{List of symbols}
\setglossarysection{section}% <- added
\printglossary[type=onelist,style=mysymbolstyle,nonumberlist,title=test 1]
\printglossary[type=twolist,style=mysymbolstyle,nonumberlist,title=test 2]

\end{document}