# Manual line break in Glossaries name

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

\newglossarystyle{superglossarystyle}
{
\setglossarystyle{super}
\renewenvironment{theglossary}
{
\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}
{
\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}

\end{document}

• Can you describe more precisely how you generated such entries. This would be best done by including a minimal working example (MWE) Sep 29, 2014 at 12:14
• You can't have a line break in a column defined with the r specifier. You'd have to switch to a paragraph specifier, such as p (as with the second column). Sep 29, 2014 at 12:28
• Okay, then how do I get something like \glsnamewidth and right-align a p{}? Sep 29, 2014 at 12:29

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.

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.

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:

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}%
{%
\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}%
{%
\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}


• Thank you, I use your example + \null\newline in front of the description of the pab-entry for better alignment (its okay for the few occourences of this, I guess it'll be much harder to do this automatically). Sep 29, 2014 at 14:02