6
Stack Exchange
votes

Glossary style with tabularray

Posted on 3/9/2023
UQ ID:398
Technology
TeX - LaTeX
Original

I am currently migrating from xltabular to tabularray. As part of that I want to adapt my custom glossary style for List of Symbols and List of Abbreviations (same style).

This is my old code:

% tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{xltabular}
\usepackage{tabularray}
\addto\captionsngerman{
    \DefTblrTemplate{contfoot-text}{default}{Fortsetzung auf der n\"achsten Seite}
    \DefTblrTemplate{conthead-text}{default}{(fortgesetzt)}
}

% glossaries
\usepackage[
    abbreviations,
    nonumberlist,
    record,
    symbols
]{glossaries-extra}
\GlsXtrLoadResources[
    src=glossaries,
    not-match={entrytype=symbol}
]
\GlsXtrLoadResources[
    selection=all,
    src=glossaries,
    type=symbols,
    match={entrytype=symbol}
]
\newglossarystyle{customlong}{
    \setglossarystyle{long}
    \renewenvironment{theglossary}{\xltabular{\textwidth}{llX}}{\endxltabular}
    \renewcommand{\glossentry}[2]{
        \glsentryitem{##1}\textbf{\glstarget{##1}{\glossentryname{##1}}} & \multicolumn{2}{X}{\glossentrydesc{##1}}\\
    }
    \renewcommand{\subglossentry}[3]{
        & \glssubentryitem{##2}\glstarget{##2}{\strut} & \glossentrydesc{##2}\\
    }
    \ifglsnogroupskip
        \renewcommand*{\glsgroupskip}{}%
    \else
        \renewcommand*{\glsgroupskip}{\\}%
    \fi
}

I would like to get rid of:

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{xltabular}

Therefore, I need to adapt \newglossarystyle{customlong}{...}. This is my current state:

\newglossarystyle{customlong}{
    \setglossarystyle{long}
    \renewenvironment{theglossary}{
        \begin{longtblr}[
            entry=none,
            label=none
        ]{
            colspec={llX},
            hspan=minimal,
            stretch=1,
            width=\textwidth
        }
    }{\end{longtblr}}
    \renewcommand{\glossentry}[2]{
        \glsentryitem{##1}\textbf{\glstarget{##1}{\glossentryname{##1}}} & \SetCell[c=2]{l}\glossentrydesc{##1}\\
    }
    \renewcommand{\subglossentry}[3]{
        & \glssubentryitem{##2}\glstarget{##2}{\strut} & \glossentrydesc{##2}\\
    }
    \ifglsnogroupskip
        \renewcommand*{\glsgroupskip}{}%
    \else
        \renewcommand*{\glsgroupskip}{\\}%
    \fi
}

Compilation fails with 'Misplaced alignment tab character &.'. When I replace & with \& in \renewcommand{\glossentry}[2]{...} and \renewcommand{\subglossentry}[3]{...}, the compilation is successful but the output obviously contains '&'.

I assume that this error is related to the following content of the package documentation of tabularray:

"In contrast to traditional tabular environment, tabularray environments need to see every & and \ when splitting the table body with l3regex. And you can not put cell text inside any table command defined with \NewTableCommand. But you could use outer key expand to make tabularray expand every occurrence of a specified macro once before splitting the table body. Note that you can not expand a command defined with \NewDocumentCommand." (https://ftp.gwdg.de/pub/ctan/macros/latex/contrib/tabularray/tabularray.pdf, p. 30)

This would mean that I need to expand \renewcommand{\glossentry}[2]{...} and \renewcommand{\subglossentry}[3]{...}. I have no idea how to achieve that. Can someone help?

Thanks in advance.

Edit 1: M(N)WE

This is my current code which prints '&'. Some unrelated contents have been removed. I build with latexmk.

main.tex

\documentclass{scrbook}

\usepackage{tabularray}

\usepackage[
    abbreviations,
    nonumberlist,
    record,
    symbols
]{glossaries-extra}
\GlsXtrLoadResources[
    src=glossaries,
    not-match={entrytype=symbol}
]
\GlsXtrLoadResources[
    selection=all,
    src=glossaries,
    type=symbols,
    match={entrytype=symbol}
]
\newglossarystyle{customlong}{
    \setglossarystyle{long}
    \renewenvironment{theglossary}{
        \begin{longtblr}[
            entry=none,
            label=none
        ]{
            colspec={llX},
            hspan=minimal,
            stretch=1,
            width=\textwidth
        }
    }{\end{longtblr}}
    \renewcommand{\glossentry}[2]{
        \glsentryitem{##1}\textbf{\glstarget{##1}{\glossentryname{##1}}} \& \SetCell[c=2]{l}\glossentrydesc{##1}\\
    }
    \renewcommand{\subglossentry}[3]{
        \& \glssubentryitem{##2}\glstarget{##2}{\strut} \& \glossentrydesc{##2}\\
    }
    \ifglsnogroupskip
        \renewcommand*{\glsgroupskip}{}%
    \else
        \renewcommand*{\glsgroupskip}{\\}%
    \fi
}
\newglossarystyle{customindex}{
    \setglossarystyle{index}
    \renewcommand{\glstreeitem}{\parindent0pt\par}
    \renewcommand{\glstreepredesc}{\par\glstreeitem\parindent40pt\hangindent40pt}
}

\begin{document}
    \frontmatter
        \printunsrtabbreviations[style=customlong]
        \printunsrtsymbols[style=customlong]

    \mainmatter

    \appendix

    \backmatter
            \printunsrtglossary[style=customindex]
\end{document}

glossaries.bib

@entry{gls-uml,
    name        = {Unified Modeling Language},
    description = {\enquote{A specification defining a graphical language for visualizing, specifying, constructing, and documenting the artifacts of distributed object systems.}\footnote{\url{https://www.omg.org/spec/UML}, aufgerufen am 20.02.2023}.}
}

@abbreviation{auv,
    description = {\gls{gls-auv}},
    short       = {AUV},
    long        = {Autonomous Underwater Vehicle}
}

@symbol{v-desired,
    name        = {\ensuremath{\overrightarrow{v_{desired}}}},
    description = {Wunschgeschwindigkeit}
}

.latexmkrc

@default_files = ('main');

$pdf_mode = 4;
$dvi_mode = 0;
$postscript_mode = 0;

$lualatex = 'lualatex -synctex=1 -interaction=nonstopmode %O %S';

push @generated_exts, 'glstex', 'glg';

$clean_ext .= ' %R.bbl %R.glstex %R.lol %R.run.xml %R-1.glstex ';

add_cus_dep( 'aux', 'glstex', 0, 'run_bib2gls' );

sub run_bib2gls {
        if ($silent) {
                my $ret = system "bib2gls --silent --group $_[0]";
        }
        else {
                my $ret = system "bib2gls --group $_[0]";
        }

        my ( $base, $path ) = fileparse( $_[0] );
        if ( $path && -e "$base.glstex" ) {
                rename "$base.glstex", "$path$base.glstex";
        }

        # Analyze log file.
        local *LOG;
        $LOG = "$_[0].glg";
        if ( !$ret && -e $LOG ) {
                open LOG, "<$LOG";
                while (<LOG>) {
                        if (/^Reading (.*\.bib)\s$/) {
                                rdb_ensure_file( $rule, $1 );
                        }
                }
                close LOG;
        }
        return $ret;
}
Keywords & Tags
glossaries
tabularray
glossaries-extra
xltabular
Model Answers (9)
Submitted answers from various AI models
Unsolved
No reviews yet

K2-Think

Pending UQ Validation
Needs Human Verification
MBZUAI-IFM
Qwen2.5-32B
Sep 18, 2025, 01:50 PM

To resolve the "Misplaced alignment tab character &." error when using tabularray for your glossary style, you need to address how tabularray processes table cells and ensure consistent cell counts. Here's the step-by-step solution:

Key Issues:

  1. Unexpanded & Characters: tabularray requires & characters to be visible when splitting table rows. Commands like \glossentry and `\su...
0 model reviews
0 human reviews
No reviews yet

GPT-5

Failed UQ Validation
Needs Human Verification
OpenAI
Sep 2, 2025, 06:56 AM

You’re right: the error comes from tabularray needing to “see” the alignment tokens (& and \) when it splits the table body. In your style, those tokens are hidden inside the macros \glossentry and \subglossentry, so tabularray doesn’t find them and throws “Misplaced alignment tab character &.”

Fix: ask tabularray to expand those macros once before it parses the table body. Use the outer key exp...

0 model reviews
0 human reviews
No reviews yet

o3

Failed UQ Validation
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

longtblr scans the source of the table with l3regex before TeX starts to expand the tokens it finds.
If a command that is not expanded during this scan (for instance \glossentry or \subglossentry) hides the characters ‘&’ or ‘\’, the parser will not see any column or row separator.
The concealed ‘&’ and ‘\’ only become visible later, when TeX finally expands the two glossar...

0 model reviews
0 human reviews
No reviews yet

Claude 3.7 Sonnet

Failed UQ Validation
Needs Human Verification
Anthropic
Aug 1, 2025, 12:00 AM

Using Tabularray with Glossaries

I understand your challenge with migrating from xltabular to tabularray for your glossary styles. The issue occurs because tabularray processes tables differently from traditional LaTeX table environments - it needs to see the actual & and \\ characters directly during parsing, rather than having them hidden inside macros.

Solution

The key is to use...

0 model reviews
0 human reviews
No reviews yet

Gemini 2.5 Pro

Failed UQ Validation
Needs Human Verification
Google
Aug 1, 2025, 12:00 AM

Of course, I can help you with that. Your diagnosis is exactly right. The tabularray environment scans its body for & and \\ before expanding macros, which causes the "Misplaced alignment tab character" error when those characters are hidden inside other commands like \glossentry.

The solution, as you suspected, is to use the expand key provided by tabularray. This key tells `tabula...

0 model reviews
0 human reviews
No reviews yet

Claude Opus 4

Failed UQ Validation
Needs Human Verification
Anthropic
Aug 1, 2025, 12:00 AM

Looking at your code, the issue is that you're trying to use tabularray environments in a way that conflicts with how glossaries generates its content. The problem is that tabularray needs to see the complete table content at once to parse it, but glossaries generates the table content dynamically through multiple calls to \glossentry and \subglossentry.

Here's a solution that works b...

0 model reviews
0 human reviews
No reviews yet

DeepSeek R1

Failed UQ Validation
Needs Human Verification
DeepSeek
deepseek-ai/DeepSeek-R1
Aug 1, 2025, 12:00 AM
<think> We are given a question about adapting a custom glossary style from using `xltabular` to `tabularray` in LaTeX. The user is encountering an error when using `&` in the glossary style commands and has tried replacing `&` with `\&` which prints the ampersand instead of being a column separator.

The issue arises because tabularray environments process the table body in a special way (using...

0 model reviews
0 human reviews
No reviews yet

o4 mini

Failed UQ Validation
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

The mysterious “Misplaced alignment tab character &” is simply tabularray telling you:

“I’ve read the body of the longtblr environment already and I’m trying to split it on every & and \\ before I actually make the cells. Since your \glossentry (and \subglossentry) still contain an un‐expanded & and \\, the splitter sees them in the wrong place.”

The way to tell tabularray to ex...

0 model reviews
0 human reviews
No reviews yet

o3 Pro

Failed UQ Validation
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

longtblr (and all the other tabularray environments) read the whole table body first and then split it at the alignment characters “&” and “\”.
If these characters are hidden inside a macro they are not visible to the splitter.
The solution that the author of tabularray provides for this situation is the outer key expand=: every macro that is mentioned in this key is expanded once...

0 model reviews
0 human reviews
Submit Your Model's Answer
Your submission will be validated by our LLM validator and then by human experts

You need to be logged in to submit an answer