0

For the following MWE

% arara: lualatex: { options: [ '-synctex=1', '-shell-escape' ]}
% arara: makeglossaries
% arara: lualatex: { options: [ '-synctex=1', '-shell-escape' ]}

\documentclass{elsarticle}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{calc,siunitx,booktabs,lipsum}
\sisetup{load-configurations = abbreviations}
\usepackage[automake,stylemods,symbols,
xindy={codepage=utf8, language=greek, glsnumbers=false}
]{glossaries-extra}

\makeglossaries

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

\newglossarystyle{nameunitdesc}{%
    \setlength{\glsdescwidth}{\linewidth-\glsnamewidth-\glsunitwidth-4\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{Cp}{name={Cp},description={specific heat}, symbol={[\si{\J\per\kg\per\K}]}}

\journal{Journal name}

\begin{document}

    \begin{frontmatter}

        \title{Title}

        \begin{abstract}

            \lipsum[1]

        \end{abstract}

    \end{frontmatter}

    \gls{Cp} 

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

    \printglossary[style=nameunitdesc,title=Nomenclature]

\end{document}

In this line \setlength{\glsdescwidth}{\linewidth-\glsnamewidth-\glsunitwidth-2\tabcolsep}, intuitively, I need to subtract 2\tabcolsep in order to make the description field span the whole line width, however, subtracting 4\tabcolsep results in the following correctly aligned right margin of the glossary table:

enter image description here

while subtracting 2\tabcolsep results in the following overflown right margin of the glossary table:

enter image description here

So, how to accurately calculate the needed number of \tabcolsep to be subtracted without trial and error?

1

This actually has nothing to do with glossaries, it is just how tabular works:

\tabcolsep is the margin that is inserted on either side of every column in the table. Thus, in the example

\begin{tabular}{ c c c }
  \hline
  a & b & c \\
  \hline
\end{tabular}

MWE output

the table extends \tabcolsep to the left of a and to the right of c (you can see the width of the table using the \hlines), while there is a space of 2\tabcolsep between a and b as well as b and c.

In your example, you remove the separations at the edges of the table using @{} and you have three columns. That makes 2 * 2\tabcolsep = 4\tabcolsep between them.

  • Thanks for your explanation. Off topic question: how to remove both separations on each side of the first column in your example while keeping all the other ones? – Diaa Jul 24 at 11:06
  • @Diaa You can use { @{} c @{\hspace{\tabcolsep}} c c } as the column specifier. – schtandard Jul 24 at 11:10
  • Thanks for help. I am always in rush and struggle a lot with latex basics :) – Diaa Jul 24 at 11:21

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.