I am trying to build a table inside a LaTeX 3 command. A MWE:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\createTable}{ m m }{
\begin{tabular}{|c*{#2}{|c}|}
\hline
\int_step_inline:nnnn {1} {1} {#1} {
##1
\int_step_inline:nnnn {1} {1} {#2} {
& x
}
\\\hline
}
\end{tabular}
}
\ExplSyntaxOff
\begin{document}
\createTable{5}{4}
\end{document}
This gives me following ouput in which the column lines of the first column are too long:
In order to solve this problem I read questions
- Too long vertical lines in table
- Too long vertical lines in table when declarations must remain on distinct lines
- Producing expandable environments with only optional arguments with LaTeX3 syntax
Though I still did not understand the actual nature of the problem (or its given solutions), I was able to reproduce the solution from Producing expandable environments with only optional arguments with LaTeX3 syntax.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\DeclareDocumentCommand{\fillRow}{ m m }{
#1
\int_step_inline:nnnn {1} {1} {#2} {
& x
}
\\\hline
}
\DeclareDocumentCommand{\BuildTable}{ m }{
\begin{tabular}{|c*{#1}{|c}|}
\hline
}
\def\endBuildTable{
\end{tabular}
}
\ExplSyntaxOff
\begin{document}
\begin{BuildTable}{4}
\fillRow{1}{4}
\fillRow{2}{4}
\fillRow{3}{4}
\fillRow{4}{4}
\fillRow{5}{4}
\end{BuildTable}
\end{document}
This code outputs the desired result. But I don't like it because it needs 3 commands instead of 1 (minor issue). But most of all because of the verbose, redundant and inflexible syntax to generate the table. Therefore I decided to make an abstraction by putting the table-generating-commands in another command:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\DeclareDocumentCommand{\fillRow}{ m m }{
#1
\int_step_inline:nnnn {1} {1} {#2} {
& x
}
\\\hline
}
\DeclareDocumentCommand{\BuildTable}{ m }{
\begin{tabular}{|c*{#1}{|c}|}
\hline
}
\def\endBuildTable{
\end{tabular}
}
\DeclareDocumentCommand{\putTogether}{ m m }{
\begin{BuildTable}{#2}
\int_step_inline:nnnn {1} {1} {#1} {
\fillRow{##1}{#2}
}
\end{BuildTable}
}
\ExplSyntaxOff
\begin{document}
\putTogether{5}{4}
\end{document}
But this brought me back to my original problem because the column lines of the first column are too long again.
Could anyone
- explain to me what exactly is wrong with my original code;
- what the difference is between the second and the third code fragments;
- how to edit my (original) code in order to solve my problem?

