The simplest solution is to change the value of \glsdescwidth
using \setlength
. For example \setlength{\glsdescwidth}{3in}
as in the following example:
\documentclass{article}
\usepackage{lipsum}
\usepackage{glossaries}
\makeglossaries
\newglossarystyle{formel_altlong4colheader}{%
\setglossarystyle{altlong4colheader}%
%
\renewcommand*{\glossaryheader}{%
\bfseries sign
& \bfseries description
& \bfseries unit
& \\
\hline
\\\endhead}%
\renewcommand{\glossentry}[2]{%
\glstarget{##1}{\glossentryname{##1}}%
& \glossentrydesc{##1}%
& \glossentrysymbol{##1}%
\tabularnewline % end of row
}%
}
\setlength{\glsdescwidth}{3in}
\setglossarystyle{formel_altlong4colheader}
\newglossaryentry{L}{name={L},description={Buchstabe},symbol={---}}
\newglossaryentry{P}{name={P},description={Leistung},symbol={kW}}
\begin{document}
\lipsum[1]
\glsaddall
\printglossaries
\end{document}
This produces:
However this approach is a matter of trial and error to work out the value of \glsdescwidth
. You also still have the fourth column, even though you're not using it, which is taking up unnecessary space. Instead I recommend a different approach that works out the width:
\documentclass{article}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{calc}
\usepackage{glossaries}
\makeglossaries
\newlength\glsnamewidth
\newlength\glsunitwidth
\settowidth{\glsnamewidth}{\textbf{sign}}
\settowidth{\glsunitwidth}{\textbf{unit}}
\newglossarystyle{namedescunit}{%
\setlength{\glsdescwidth}{\linewidth-\glsnamewidth-\glsunitwidth-6\tabcolsep}%
\renewenvironment{theglossary}%
{\begin{longtable}{p{\glsnamewidth}p{\glsdescwidth}p{\glsunitwidth}}}%
{\end{longtable}}%
\renewcommand*{\glossaryheader}{%
\bfseries sign
& \bfseries description
& \bfseries unit
\tabularnewline
\midrule
\tabularnewline\endhead}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand{\glossentry}[2]{%
\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1} &
\glossentrysymbol{##1}\tabularnewline
}%
\renewcommand{\subglossentry}[3]{\glossentry{##2}{##3}}%
\renewcommand*{\glsgroupskip}{}%
}
\setglossarystyle{namedescunit}
\newglossaryentry{L}{name={L},description={Buchstabe},symbol={---}}
\newglossaryentry{P}{name={P},description={Leistung},symbol={kW}}
\begin{document}
\lipsum[1]
\glsaddall
\printglossaries
\end{document}
This produces:
This assumes that the maximum widths of the first and third columns are given by their header text. This may not be the case, so the following example computes them as the entries are defined:
\documentclass{article}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{calc}
\usepackage{glossaries}
\makeglossaries
\newlength\glsnamewidth
\newlength\glsunitwidth
\settowidth{\glsnamewidth}{\textbf{sign}}
\settowidth{\glsunitwidth}{\textbf{unit}}
\newglossarystyle{namedescunit}{%
\setlength{\glsdescwidth}{\linewidth-\glsnamewidth-\glsunitwidth-6\tabcolsep}%
\renewenvironment{theglossary}%
{\begin{longtable}{p{\glsnamewidth}p{\glsdescwidth}p{\glsunitwidth}}}%
{\end{longtable}}%
\renewcommand*{\glossaryheader}{%
\bfseries sign
& \bfseries description
& \bfseries unit
\tabularnewline
\midrule
\tabularnewline\endhead}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand{\glossentry}[2]{%
\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1} &
\glossentrysymbol{##1}\tabularnewline
}%
\renewcommand{\subglossentry}[3]{\glossentry{##2}{##3}}%
\renewcommand*{\glsgroupskip}{}%
}
\setglossarystyle{namedescunit}
\makeatletter
\appto\@newglossaryentryposthook{%
\settowidth{\dimen@}{\glsentryname{\@glo@label}}%
\ifdim\dimen@>\glsnamewidth
\setlength{\glsnamewidth}{\dimen@}%
\fi
\settowidth{\dimen@}{\glsentrysymbol{\@glo@label}}%
\ifdim\dimen@>\glsunitwidth
\setlength{\glsunitwidth}{\dimen@}%
\fi
}%
\makeatother
\newglossaryentry{L}{name={L},description={Buchstabe},symbol={---}}
\newglossaryentry{P}{name={P},description={Leistung},symbol={kW}}
\begin{document}
\lipsum[1]
\glsaddall
\printglossaries
\end{document}
In this case, the result is the same as the previous example. If you want the name and unit columns centred you can add \centering
to the style:
\documentclass{article}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{calc}
\usepackage{glossaries}
\makeglossaries
\newlength\glsnamewidth
\newlength\glsunitwidth
\settowidth{\glsnamewidth}{\textbf{sign}}
\settowidth{\glsunitwidth}{\textbf{unit}}
\newglossarystyle{namedescunit}{%
\setlength{\glsdescwidth}{\linewidth-\glsnamewidth-\glsunitwidth-6\tabcolsep}%
\renewenvironment{theglossary}%
{\begin{longtable}{p{\glsnamewidth}p{\glsdescwidth}p{\glsunitwidth}}}%
{\end{longtable}}%
\renewcommand*{\glossaryheader}{%
\centering\bfseries sign
& \bfseries description
& \centering\bfseries unit
\tabularnewline
\midrule
\tabularnewline\endhead}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand{\glossentry}[2]{%
\centering\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1} &
\centering\glossentrysymbol{##1}\tabularnewline
}%
\renewcommand{\subglossentry}[3]{\glossentry{##2}{##3}}%
\renewcommand*{\glsgroupskip}{}%
}
\setglossarystyle{namedescunit}
\makeatletter
\appto\@newglossaryentryposthook{%
\settowidth{\dimen@}{\glsentryname{\@glo@label}}%
\ifdim\dimen@>\glsnamewidth
\setlength{\glsnamewidth}{\dimen@}%
\fi
\settowidth{\dimen@}{\glsentrysymbol{\@glo@label}}%
\ifdim\dimen@>\glsunitwidth
\setlength{\glsunitwidth}{\dimen@}%
\fi
}%
\makeatother
\newglossaryentry{L}{name={L},description={Buchstabe},symbol={---}}
\newglossaryentry{P}{name={P},description={Leistung},symbol={kW}}
\begin{document}
\lipsum[1]
\glsaddall
\printglossaries
\end{document}
This now produces:
The problem here is that you're mixing old and new commands. My original answer that you linked to is several years old and uses commands that are now deprecated, such as \glossarystyle
and \glossaryentryfield
. Your MWE has changed the deprecated \glossarystyle
to \setglossarystyle
but hasn't changed the deprecated \glossaryentryfield
. By using the new \setglossarystyle
, the backward-compatibility is removed and \glossaryentryfield
isn't used.
To fix it, just replace \glossaryentryfield
with the newer \glossentry
:
\renewcommand*{\glossentry}[2]{%
\edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
\doifinlocation
{%
\item \glossentryname{##1} \glossentrydesc{##1}%
}%
}%
Complete MWE:
\documentclass{report}
\usepackage{datatool-base}
\usepackage[counter=chapter,xindy,section=section]{glossaries}
\GlsSetXdyMinRangeLength{0}
\makeglossaries
\newglossaryentry{E}{name={\ensuremath{E}},description={energy}}
\newglossaryentry{m}{name={\ensuremath{m}},description={mass}}
\newglossaryentry{c}{name={\ensuremath{c}},description={speed of light}}
\newglossaryentry{v}{name={\ensuremath{v}},description=velocity}
\newglossarystyle{mystyle}%
{%
\setglossarystyle{list}%
\renewcommand*{\glossaryentrynumbers}[1]{\striprelax##1\endstriprelax}%
\renewcommand*{\glsXchapterXglsnumberformat}[2]{##2}%
\renewcommand*{\delimR}{,}%
\renewcommand*{\glossentry}[2]{%
\edef\doifinlocation{\noexpand\ifinlocation{\thechapter}{##2}}%
\doifinlocation
{%
\item \glossentryname{##1} \glossentrydesc{##1}%
}%
}%
}
\newcommand{\ifinlocation}[3]{%
\DTLifinlist{#1}{#2}{#3}{}%
}
\def\striprelax\relax#1\endstriprelax{#1}
\setglossarystyle{mystyle}
\begin{document}
\chapter{Sample Chapter}
\printglossary
\begin{equation}
\gls{E} = \gls{m}\cdot \gls{c}^2
\end{equation}
\glsresetall
\chapter{Another Chapter}
\printglossary
\begin{equation}
\gls{E} = \frac{\gls{m}\gls{v}^2}{2}
\end{equation}
\end{document}
First chapter:
Second chapter:
Best Answer
You can use a style based upon the
long
style (which actually is alongtable
. I used 3cm instead of 5cm; that looks enough.