6

Consider the following Latex3 example usage of \clist_map_inline:nn:

\documentclass[margin=0.1cm]{standalone}
\usepackage{expl3}
\begin{document}
\begin{tabular}{|c|c|}
    \hline%
    \ExplSyntaxOn%
        \clist_map_inline:nn {A,B,C,D}%
            {#1: & something \\\hline}%
    \ExplSyntaxOff%
\end{tabular}

\begin{tabular}{|c|c|}
    \hline%
    \ExplSyntaxOn%
        \clist_map_inline:nn {A,B,C}%
            {#1: & something \\\hline}%
    \ExplSyntaxOff%
    D: & something \\\hline
\end{tabular}
\end{document}

Result:

enter image description here

Why does the first table have an extra empty row at the bottom?

0

2 Answers 2

4

You can avoid the issue with \clist_use:Nn:

\documentclass[margin=0.1cm]{standalone}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\makerow}{mm}
 {
  \clist_set:Nn \l_tmpa_clist { #1 }
  \clist_use:Nn \l_tmpa_clist { #2 }
  #2
 }
\ExplSyntaxOff

\begin{document}

\begin{tabular}{|c|c|}
\hline
\makerow{A,B,C,D}{& something \\\hline}
\end{tabular}

\begin{tabular}{|c|c|}
\hline
\makerow{A,B,C}{& something \\\hline}
D: & something \\\hline
\end{tabular}

\end{document}

enter image description here

The problem with \clist_map_inline:nn is that it leaves TeX in the state where a new cell has already been started.

1

As egreg said:

it leaves TeX in the state where a new cell has already been started.

I think it's because your \clist_map_inline:nn put in the tabular environment, so If you still want use map (for programming), you can generate content of table before goto tabular.

\documentclass{article}
\usepackage{expl3}
\begin{document}.

    \ExplSyntaxOn
    % A variable for save contents.
    \tl_gclear_new:N \g_thomas_tableContent_tl

    \clist_map_inline:nn {A,B,C,D}{
        \tl_gput_right:Nx \g_thomas_tableContent_tl {
            #1: & something \exp_not:n {\\ \hline}
        }
    }
    % Copy to LaTeX2e's macro.'
    \cs_gset_eq:NN \tableContent \g_thomas_tableContent_tl
    \ExplSyntaxOff

    \begin{tabular}{|c|c|}
        \hline
        \tableContent
    \end{tabular}
\end{document}

Note, for \tl_gput_right: I used Nx with \exp_not:n {\\ \hline}. Because I need use variable (\l_tmpa_tl) in my table, it need expansion. You can use Nn also, if you don't expansion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .