[Tex/LaTex] Glossary style ‘long’

glossarieslongtable

I have made a symbollist with the glossary package. Here is the code:

\documentclass[12pt]{article} 

\usepackage[utf8]{inputenc} %Inputencoding: Umlaute richtig eingeben
\usepackage[T1]{fontenc}    %Fontencoding: Worte mit Umlauten richtig trennen
\usepackage[ngerman]{babel} 
\usepackage{acronym}
\usepackage{hyperref}

\usepackage[
nonumberlist, %keine Seitenzahlen anzeigen
nogroupskip,  %kein Abstand
acronym,      %ein Abkürzungsverzeichnis erstellen
toc,          %Einträge im Inhaltsverzeichnis
section]      %im Inhaltsverzeichnis auf section-Ebene erscheinen
{glossaries}


%Ein eigenes Symbolverzeichnis erstellen
\newglossary[slg]{symbolslist}{syi}{syg}{Symbolverzeichnis}
\newglossary[slg]{acronyms}{syi}{syg}{Abkürzungsverzeichnis}

%Den Punkt am Ende jeder Beschreibung deaktivieren
\renewcommand*{\glspostdescription}{}


%eigenen glossaries style für symbolverzeichnis definieren
\newglossarystyle{superAB}{% 
\glossarystyle{long}%
\newcommand*{\myglossaryindent}{0cm}% linker Seitenabstand symbolverzeichnis %symbolverzeichnis nach links einrücken --------------------

\renewenvironment{theglossary}
{%
\begin{longtable}[l]{@{\hspace{\myglossaryindent}}lp{\glsdescwidth}}%
}%
% 
{\end{longtable}% 
}
\renewcommand*{\glossarysubentryfield}[6]{%
##3 & \glssubentryitem{##2}\glstarget{##2}{\strut}##4\glspostdescription\\}
}%

%symbolverzeichnis nach links einrücken 


%Glossar-Befehle anschalten
\makeglossaries

%%%%%%%%%%%%%%%%%%%%%%%%%%Settings%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\setlength{\glslistdottedwidth}{.25\hsize} %Punktlänge einstellen

\newglossaryentry{romanletter}{name={\textbf{\large Lateinische Symbole}},description={}}
\newglossaryentry{greekletter}{name={\textbf{\large Griechische Symbole}},description={}}

\newglossaryentry{symb:omega}{
name=$\Omega$,
description={Giergeschwindigkeit},
parent=greekletter,
sort=symbolomega, 
type=symbolslist
}
\newglossaryentry{symb:M0}{
name=$M_{\mathrm{0}}$,
description={gemessenes Biegemoment mittels Vollmessbrücken DMS Schaltung},
parent=romanletter,
sort=symbolM0, 
type=symbolslist
}

\glsaddall[types=symbolslist]

\begin{document}
\printglossary[type=symbolslist, style=superAB]
\end{document}

It looks like this:
enter image description here

But I want to change some things:
1.) Increase the distance between the last greec symbol and the caption of the roman symbols
2.) the distance between the symbol and the description should be smaller
3.) the distance between the symbol and the description should be dotted.

In the end it should look like this:
enter image description here

Thank you in advance!

Best Answer

The main problem here is that the top level entries (denoting the Greek and Latin entries) are in the first column of the table, so that column must be at least as wide as those headings. There are a number of ways to resolve this.

The first method adjusts the style to make the top-level entries span both columns. It's more efficient to move the font changing commands out of the name field and put them in the style. This assumes that all your top-level entries are actually headers.

Note that as from version 4.0, the style commands \glossarystyle, \glossaryentryfield and \glossarysubentryfield are all deprecated. You can still use them but you'll get a warning. To update to the newer commands, you need to make the following substitutions:

  • \glossarystyle{style-name} -> \setglossarystyle{style-name}
  • \glossaryentryfield{label}{name}{description}{symbol}{location} replace with:

    \glossentry{label}{location}

    • The name can be accessed with \glossentryname{label}.
    • The description can be accessed with \glossentrydesc{label}.
    • The symbol can be accessed with \glossentrysymbol{label}.
    • Other fields can be accessed with commands like \glsentryuseri{label} described in section 9: Using Glossary Terms Without Links of the user manual.
  • \glossarysubentryfield{level}{label}{name}{description}{symbol}{location} replace with:

    \subglossentry{level}{label}{location}

    The fields can be accessed as above.

Here's a modified version that uses the newer commands and makes the top-level entries span both columns:

\documentclass[12pt]{article} 

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel} 
\usepackage{hyperref}

\usepackage[
nonumberlist,
nogroupskip,
nopostdot,
toc,
section]
{glossaries}


\newglossary[slg]{symbolslist}{syi}{syg}{Symbolverzeichnis}

\newglossarystyle{superAB}{% 
 \setglossarystyle{long}%
 \renewenvironment{theglossary}
 {%
  \begin{longtable}[l]{@{}lp{\glsdescwidth}}%
 }%
 {%
   \end{longtable}% 
 }%
 \renewcommand{\glossentry}[2]{%
   \tabularnewline
   \multicolumn{2}{@{}l}%
   {%
     \glsentryitem{##1}%
     \glstarget{##1}{\textbf{\large\glossentryname{##1}}}%
   }%
   \tabularnewline
 }%
 \renewcommand{\subglossentry}[3]{%
    \glssubentryitem{##2}%
    \glstarget{##2}{\glossentryname{##2}}%
    &
    \glossentrydesc{##2}\glspostdescription\space
    ##3\tabularnewline
 }%
}%

\makeglossaries

\newglossaryentry{romanletter}{name={Lateinische Symbole},description={}}
\newglossaryentry{greekletter}{name={Griechische Symbole},description={}}

\newglossaryentry{symb:omega}{
name=$\Omega$,
description={Giergeschwindigkeit},
parent=greekletter,
sort=symbolomega, 
type=symbolslist
}
\newglossaryentry{symb:M0}{
name=$M_{\mathrm{0}}$,
description={gemessenes Biegemoment mittels Vollmessbrücken DMS Schaltung},
parent=romanletter,
sort=symbolM0, 
type=symbolslist
}

\glsaddall[types=symbolslist]

\begin{document}
\printglossary[type=symbolslist, style=superAB]
\end{document}

The result is:

image of symbol list

The first column is now just wide enough to fit the widest sub-entry. A dotted leader can be added to the style with \dotfill but it will be barely noticeable with just a single dot for the narrower symbol (omega).

Here's a variation that makes the left column 2cm wide and adds a leader:

\newglossarystyle{superAB}{% 
 \setglossarystyle{long}%
 \renewenvironment{theglossary}
 {%
  \begin{longtable}[l]{@{}p{2cm}p{\glsdescwidth}}%
 }%
 {%
   \end{longtable}% 
 }%
 \renewcommand{\glossentry}[2]{%
   \tabularnewline
   \multicolumn{2}{@{}l}%
   {%
     \glsentryitem{##1}%
     \glstarget{##1}{\textbf{\large\glossentryname{##1}}}%
   }%
   \tabularnewline
 }%
 \renewcommand{\subglossentry}[3]{%
    \glssubentryitem{##2}%
    \glstarget{##2}{\glossentryname{##2}}%
    \dotfill
    &
    \glossentrydesc{##2}\glspostdescription\space
    ##3\tabularnewline
 }%
}%

This produces:

image of symbol list with dotted leader

The gap between the columns can be shrunk by reducing the value of \tabcolsep. For example:

\newglossarystyle{superAB}{% 
 \setglossarystyle{long}%
 \renewenvironment{theglossary}
 {%
  \setlength{\tabcolsep}{2pt}%
  \begin{longtable}[l]{@{}p{2cm}p{\glsdescwidth}}%
 }%
 {%
   \end{longtable}% 
 }%
 \renewcommand{\glossentry}[2]{%
   \tabularnewline
   \multicolumn{2}{@{}l}%
   {%
     \glsentryitem{##1}%
     \glstarget{##1}{\textbf{\large\glossentryname{##1}}}%
   }%
   \tabularnewline
 }%
 \renewcommand{\subglossentry}[3]{%
    \glssubentryitem{##2}%
    \glstarget{##2}{\glossentryname{##2}}%
    \dotfill
    &
    \glossentrydesc{##2}\glspostdescription\space
    ##3\tabularnewline
 }%
}%

This produces:

image of symbol list with narrow gap between columns

Alternatively, you can remove it completely with @{} in the column specifier:

  \begin{longtable}[l]{@{}p{2cm}@{}p{\glsdescwidth}}%

Or to use up the entire line width:

  \begin{longtable}[l]{@{}p{2cm}@{}p{\dimexpr\linewidth-2cm}@{}}%

The second method is to remove the hierarchy and have separate glossaries for each type of symbol and use the alttree style. For example:

\documentclass[12pt]{article} 

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel} 
\usepackage{hyperref}

\usepackage[
nonumberlist,
nogroupskip,
nopostdot,
toc,
section]
{glossaries}


\newglossary*{greeklist}{Griechische Symbole}
\newglossary*{romanlist}{Lateinische Symbole}

\makeglossaries

\newglossaryentry{symb:omega}{
name=$\Omega$,
description={Giergeschwindigkeit},
sort=symbolomega, 
type=greeklist
}
\newglossaryentry{symb:M0}{
name=$M_{\mathrm{0}}$,
description={gemessenes Biegemoment mittels Vollmessbrücken DMS Schaltung},
sort=symbolM0, 
type=romanlist
}

\glsaddall[types={greeklist,romanlist}]

\begin{document}

\section*{Symbolverzeichnis}
\setupglossaries{section=subsection}
\setglossarystyle{alttree}

% Set up the way the name is displayed in the alttree style and how
% much space it takes up.
\glssetwidest{MMMM}
\renewcommand*{\glstreenamebox}[2]{% requires v4.19+
  \makebox[#1][l]{#2\dotfill}%
}

\printglossary[type=greeklist]
\printglossary[type=romanlist]
\end{document}

This produces:

image of symbol lists

This method means that you manually order the two symbol lists, which makes it easier to have the Latin list before the Greek list if you prefer.

The third method is only available with the glossaries-extra extension package using the group field and \printunsrtglossary. You can manually arrange the symbols so that they are listed in order of definition (no external tool required):

\documentclass[12pt]{article} 

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel} 
\usepackage{hyperref}

\usepackage[record,% make group field available
 symbols,
 style=alttreegroup,
 nonumberlist]{glossaries-extra}

% Requires glossaries-extra.sty v1.14+
\glsxtrsetgrouptitle{greek}{Griechische Symbole}
\glsxtrsetgrouptitle{roman}{Lateinische Symbole}

\newglossaryentry{symb:omega}{
 name=$\Omega$,
 description={Giergeschwindigkeit},
 type=symbols,
 group=greek
}
\newglossaryentry{symb:M0}{
 name=$M_{\mathrm{0}}$,
 description={gemessenes Biegemoment mittels Vollmessbrücken DMS Schaltung},
 type=symbols,
 group=roman
}

% Set up the way the name is displayed in the alttree style and how
% much space it takes up.
\glssetwidest{MMMM}
\renewcommand*{\glstreenamebox}[2]{% requires v4.19+
  \makebox[#1][l]{#2\dotfill}%
}

\begin{document}

% Requires glossaries-extra.sty v1.08+
\printunsrtglossary[type=symbols,title={Symbolverzeichnis}]
\end{document}

This produces:

image of symbol list

If you want the sorting performed by an external tool, you can combine this method with bib2gls but this is currently not available with Overleaf. (For a similar example, see the sample-textsymbols.tex document described in the "Examples" chapter of the bib2gls documentation.)

Related Question