4

I figured out how to add the toprule to this glossary, but I failed to do the same for the bottomrule. So, for this MWE, I have two questions:

  1. How can I add a bottomrule at the end of the glossary?
  2. How to control the vertical skip between the toprule and bottomrule, and the first and last entries, respectively?,

finding that \toprule\\[-\baselineskip] has no effect at all as if it is written \toprule\\[0em], which needs some explanation why \\[-\baselineskip] is not fetched as expected.

\documentclass{article}
\usepackage{booktabs}
\usepackage{calc,siunitx}
\sisetup{load-configurations = abbreviations}
\usepackage[stylemods]{glossaries-extra}

\makenoidxglossaries

\newlength\glsnamewidth
\newlength\glsunitwidth
\settowidth{\glsnamewidth}{\textbf{sign}}
\settowidth{\glsunitwidth}{\textbf{unit}}

\newglossarystyle{nameunitdesc}{%
  \setlength{\glsdescwidth}{\linewidth-\glsnamewidth-\glsunitwidth-6\tabcolsep}%
  \renewenvironment{theglossary}%
    {\begin{supertabular}{@{}p{\glsnamewidth}p{\glsunitwidth}p{\glsdescwidth}@{}}}%
    {\end{supertabular}}%
 \renewcommand*{\glossaryheader}{%
    \toprule\\[-\baselineskip]% it strangely has the same effect of \\[0em]
 }%
  \renewcommand*{\glsgroupheading}[1]{}%
  \renewcommand{\glossentry}[2]{%
    \raggedright\glstarget{##1}{\glossentryname{##1}} & 
    \centering\glossentrysymbol{##1} &
    \glossentrydesc{##1}\tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{\glossentry{##2}{##3}}%
  \renewcommand*{\glsgroupskip}{}%
}

\glsnoexpandfields

\newglossaryentry{L}{name={L},description={some text},symbol={---}}
\newglossaryentry{P}{name={Cp},description={specific heat}, symbol={[\si{\J\per\kg\per\K}]}}

\begin{document}

\gls{L}, \gls{P}.

\glsFindWidestUsedAnyNameSymbol{\glsunitwidth}
\settowidth{\dimen0}{\glsgetwidestname}
\ifdim\dimen0>\glsnamewidth
    \glsnamewidth=\dimen0
\fi

\printnoidxglossary[style=nameunitdesc,sort=use]

\end{document}
2
+50

You can set the lines inside of the definition of {theglossary}:

  \renewenvironment{theglossary}%
    {\begin{supertabular} {@{}p{\glsnamewidth}p{\glsunitwidth}p{\glsdescwidth}@{}}\toprule}%
    {\bottomrule\end{supertabular}}%

With \\[-\baselineskip] you experience normal LaTeX table behaviour: A negative argument is effictively ignored here because the optional argument would be implemented as a line with negative depth, but during box packaging TeX sets the depth of a hbox to at least zero. You can avoid this problem by controlling spacing using the booktabs command \addlinespace instead of having to insert a line and going back with -\baselineskip. In the example I used it to add 5pt of vertical space below the top line:

\documentclass{article}
\usepackage{booktabs}
\usepackage{calc,siunitx}
\sisetup{load-configurations = abbreviations}
\usepackage[stylemods]{glossaries-extra}

\makenoidxglossaries

\newlength\glsnamewidth
\newlength\glsunitwidth
\settowidth{\glsnamewidth}{\textbf{sign}}
\settowidth{\glsunitwidth}{\textbf{unit}}

\newglossarystyle{nameunitdesc}{%
  \setlength{\glsdescwidth}{\linewidth-\glsnamewidth-\glsunitwidth-6\tabcolsep}%
  \renewenvironment{theglossary}%
    {\begin{supertabular}{@{}p{\glsnamewidth}p{\glsunitwidth}p{\glsdescwidth}@{}}\toprule\addlinespace[5pt]}%
    {\bottomrule\end{supertabular}}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{}%
  \renewcommand{\glossentry}[2]{%
    \raggedright\glstarget{##1}{\glossentryname{##1}} & 
    \centering\glossentrysymbol{##1} &
    \glossentrydesc{##1}\tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{\glossentry{##2}{##3}}%
  \renewcommand*{\glsgroupskip}{}%
}

\glsnoexpandfields

\newglossaryentry{L}{name={L},description={some text},symbol={---}}
\newglossaryentry{P}{name={Cp},description={specific heat}, symbol={[\si{\J\per\kg\per\K}]}}

\begin{document}

\gls{L}, \gls{P}.

\glsFindWidestUsedAnyNameSymbol{\glsunitwidth}
\settowidth{\dimen0}{\glsgetwidestname}
\ifdim\dimen0>\glsnamewidth
    \glsnamewidth=\dimen0
\fi

\printnoidxglossary[style=nameunitdesc,sort=use]

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.