2

I defined glossarystyle with longtable environment as in MWE:

\documentclass{article}
\usepackage[nopostdot,nonumberlist,acronym]{glossaries-extra}

\renewcommand{\newacronym}[3]{%
    \newglossaryentry{#1}{%
        type=acronym, 
        name=#2,
        description={#3},
        first={{#3} ({#2})},
    }
}

\newglossarystyle{acronym}
{%
    \setglossarystyle{long}
    \renewenvironment{theglossary}%
 {\begin{longtable}[l]{p{0.13\textwidth}p{0.05\textwidth}p{0.82\textwidth}}}%
          {\end{longtable}}
    \renewcommand{\glossentry}[2]{%
        \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
        — & \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
    }%
}


\newacronym{PNG}{PNG}          {Portable Network Graphics }
\newacronym{SVG}{SVG}        {Scalable Vector Graphics}
\newacronym{JPEG}{JPEG}        {Joint Photographic Experts Group}

\makeglossaries

\begin{document}

    \glsaddall
    \printglossary[type=acronym,style=acronym,title={}] 

    First use of \gls{JPEG} and \gls{PNG}. Second use of \gls{PNG} and \gls{JPEG}.

\end{document}

And it works well. One day, I decided to change longtable to xltabular, like this:

\documentclass{article}
\usepackage[nopostdot,nonumberlist,acronym]{glossaries-extra}
\usepackage{xltabular}


\renewcommand{\newacronym}[3]{%
    \newglossaryentry{#1}{%
        type=acronym, 
        name=#2,
        description={#3},
        first={{#3} ({#2})},
    }
}

\newglossarystyle{acronym}
{%
    \setglossarystyle{long}
    \renewenvironment{theglossary}%
    {\begin{xltabular}{\textwidth}{|l|c|X|}}%
        {\end{xltabular}}%
    \renewcommand{\glossentry}[2]{%
        \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
        — & \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
    }%
}


\newacronym{PNG}{PNG}          {Portable Network Graphics }
\newacronym{SVG}{SVG}        {Scalable Vector Graphics}
\newacronym{JPEG}{JPEG}        {Joint Photographic Experts Group}

\makeglossaries

\begin{document}

    \glsaddall
    \printglossary[type=acronym,style=acronym,title={}] 

    First use of \gls{JPEG} and \gls{PNG}. Second use of \gls{PNG} and \gls{JPEG}.

\end{document}

I got some errors:

File ended while scanning use of \TX@get@body. ...lossary[type=acronym,style=acronym,title={}]

\begin{xltabular} on input line 2 ended by \end{document}. \end{document}

I suggest, that errors caused by different number of non-optional arguments in longtable and xltabular, but can't get a clue to fix this.

2 Answers2

1

Thanks to this answer I got the solution.

\documentclass{article}
\usepackage[nopostdot,nonumberlist,acronym]{glossaries-extra}
\usepackage{xltabular}
\usepackage{environ}        % Used to define custom table environment

\renewcommand{\newacronym}[3]{%
    \newglossaryentry{#1}{%
        type=acronym, 
        name=#2,
        description={#3},
        first={{#3} ({#2})},
    }
}

\NewEnviron{doctable}{%
    \begin{xltabular}{\textwidth}{lcX}%
        \BODY
    \end{xltabular}
}

\newglossarystyle{acronym}
{%
    \setglossarystyle{long}
    \renewenvironment{theglossary}
{%
    \doctable
}{
    \enddoctable
}
    \renewcommand{\glossentry}[2]{%
        \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
        — & \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
    }%
}


\newacronym{PNG}{PNG}          {Portable Network Graphics }
\newacronym{SVG}{SVG}        {Scalable Vector Graphics}
\newacronym{JPEG}{JPEG}        {Joint Photographic Experts Group}

\makeglossaries

\begin{document}

    \glsaddall
    \printglossary[type=acronym,style=acronym,title={}] 

    First use of \gls{JPEG} and \gls{PNG}. Second use of \gls{PNG} and \gls{JPEG}.

\end{document}
1

If you have a table / glossary that you want to span over more than one page and want the ability to dynamically adjust the column width by using X in the table, xltabular is a very good option. It has also solved this issue for me!

Unfortunately, it's not possible to use the \begin{xltabular} and \end{xltabular} inside of new environment definitions. However, you can use \xltabular{\linewidth}{...} and \endxltabular.

This is what a three-column glossary style with variable column width could look like:

% --------------------------------------------------------------------------------
% Style of the Symbols List
% --------------------------------------------------------------------------------
\newglossarystyle{symbstyle} {
    \setglossarystyle{long3col}  % base this style on the list style
    \renewenvironment{theglossary} {
        % Change the table type --> 3 columns
        \xltabular{\linewidth}{p{0.2\textwidth}Xp{0.1\textwidth}}
    }{
        \endxltabular
    }
%  Change the table header / footer
\renewcommand*{\glossaryheader} {
    \bfseries Head1 & \bfseries Head2 & \bfseries Head3 \\
    \hline \endfirsthead
    \hline \endfoot
}

% Change the displayed items
\renewcommand*{\glossentry}[2] {
    \glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1} & \glspostdescription{##1} \\
    %               Head1                        Head2                 Head3
}

}

Hope that helps someone out there!

Alex
  • 11