[Tex/LaTex] Manual line break in Glossaries name

glossariesline-breaking

I found somewhere here a way to define my own glossary-style:

\newglossarystyle{superglossarystyle}
{
    \setglossarystyle{super}
    \renewenvironment{theglossary}
    {
        \tablehead{}
        \tabletail{}
        \begin{supertabular}{rp{\glsdescwidth}}
    }
    {
        \end{supertabular}
    }
}
%
\setglossarystyle{superglossarystyle}

How do I manually break a line in the name-field in \newglossaryentry?

How it looks now:

ParameterA,ParameterB  This is the description of ParameterA and ParameterB,
                       that is long and automatically wraps.

           ParameterC  This is the description of ParameterC, that is long
                       and automatically wraps.

How it should look:

ParameterA,
ParameterB   This is the description of ParameterA and ParameterB,
             that is long and automatically wraps.

ParameterC   This is the description of ParameterC, that is long
             and automatically wraps.

I tried to add \\,\linebreak,\tabbreak etc. as a line break without any success.

\documentclass[pdftex,a4paper,oneside,12pt,halfparskip]{scrbook}
\usepackage[]{amsmath,amssymb}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3.6cm,bottom=3.6cm,left=3.6cm,right=3.6cm]{geometry}
\usepackage[]{glossaries}

\newglossarystyle{superglossarystyle}
{
    \setglossarystyle{super}
    \renewenvironment{theglossary}
    {
        \tablehead{}
        \tabletail{}
        \begin{supertabular}{cp{\glsdescwidth}}
    }
    {
        \end{supertabular}
    }
}

\setglossarystyle{superglossarystyle}
\makeglossaries

\newglossaryentry{pab}
{
    name        = {$\boldsymbol{ParameterA},\boldsymbol{ParameterB}$} ,
    description = {This is the description of ParameterA and ParameterB, that is long and automatically wraps} ,
}

\newglossaryentry{pc}
{
    name        = {$\boldsymbol{ParameterC}$} ,
    description = {This is the description of ParameterC, that is long and automatically wraps.} ,
}

\begin{document}

\glsaddallunused\printglossaries

\end{document}

Best Answer

The standard column specifiers are l, r, c and p{length}. You can define new column types using the array package, but I don't think that's needed in this case as you can adjust the paragraph alignment using \raggedleft. When defining a new glossary style, it helps to consider a simplified version of what that style does. At it's basic level, the style needs to be in the form:

\documentclass{article}

\begin{document}
\begin{tabular}{p{2cm}p{4cm}}
\raggedleft A. & some text\\
\raggedleft AA. & some more text\\
\raggedleft AAA. & some more text
\end{tabular}

\end{document}

which has a right-aligned paragraph-style first column.

Image where first column is right aligned

Now test what happens if ParameterA,ParameterB is added:

\documentclass{article}

\begin{document}
\begin{tabular}{p{2cm}p{4cm}}
\raggedleft A. & some text\\
\raggedleft AA. & some more text\\
\raggedleft AAA. & some more text\\
\raggedleft ParameterA,ParameterB & some text
\end{tabular}

\end{document}

This doesn't have a line wrap because TeX can't insert a line break, so the result is rather ugly.

Image with overfull line

Instead you need to provide TeX with some scope to break the line at the comma:

\documentclass{article}

\newcommand{\comma}{,\penalty \exhyphenpenalty}

\begin{document}

\begin{tabular}{p{2cm}p{4cm}}
\raggedleft A. & some text\\
\raggedleft AA. & some more text\\
\raggedleft ParameterA\comma ParameterB & some text
\end{tabular}

\end{document}

TeX can now break the line:

Image with line break after comma

Here I've hardcoded the column widths using 2cm and 4cm, but the glossaries package defines a length for the second column called \glsdescwidth. You can define another length to use for the first column:

\newlength\glsnamewidth

You'll need to set this value as appropriate for your document. For example:

\setlength{\glsnamewidth}{3cm}

or

\setlength{\glsnamewidth}{0.3\hsize}

The new glossary style can then be defined as:

\newglossarystyle{superglossarystyle}
{%
  \setglossarystyle{super}%
  \renewenvironment{theglossary}%
  {%
      \tablehead{}%
      \tabletail{}%
      \begin{supertabular}{p{\glsnamewidth}p{\glsdescwidth}}%
  }%
  {%
      \end{supertabular}%
  }%
  \renewcommand{\glossentry}[2]{%
    \raggedleft
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
  }%
}

The complete example is:

\documentclass[pdftex,a4paper,oneside,12pt,halfparskip]{scrbook}
\usepackage[]{amsmath,amssymb}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3.6cm,bottom=3.6cm,left=3.6cm,right=3.6cm]{geometry}
\usepackage[]{glossaries}

\newcommand{\comma}{,\penalty \exhyphenpenalty}
\newlength\glsnamewidth
\setlength{\glsnamewidth}{0.3\hsize}

\newglossarystyle{superglossarystyle}
{%
  \setglossarystyle{super}%
  \renewenvironment{theglossary}%
  {%
      \tablehead{}%
      \tabletail{}%
      \begin{supertabular}{p{\glsnamewidth}p{\glsdescwidth}}%
  }%
  {%
      \end{supertabular}%
  }%
  \renewcommand{\glossentry}[2]{%
    \raggedleft
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
  }%
}

\setglossarystyle{superglossarystyle}
\makeglossaries

\newglossaryentry{pab}
{
    name        =
{$\boldsymbol{ParameterA}\comma\boldsymbol{ParameterB}$} ,
    description = {This is the description of ParameterA and
ParameterB, that is long and automatically wraps} ,
}

\newglossaryentry{pc}
{
    name        = {$\boldsymbol{ParameterC}$} ,
    description = {This is the description of ParameterC, that is
long and automatically wraps.} ,
}

\begin{document}

\glsaddallunused\printglossaries

\end{document}

which produces:

Image of glossary