# xltabular produces error in combination with multicolumn and \kill

What I need to do is to set 20 columns with equal width and use each one of them with multicolumn. In order to spread the table to \textwidth I need to use \kill. Explanation can be found here Tabularx (xltabular) with only multicolumns not spreading properly

Now I get this error ! Missing } inserted. This happens only when xltabular is used in combination with multicolumn, column of type X and a the command \kill. This happens in environment pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017), works fine under pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 20.12)

Anyone have a clue how to solve this ? Or even better. How to define a table with equal columns and use portions of them with multicolumn ? The thing is that I don't know the length in the cells.

  %--LATEX-COMPILER:lualatex:LATEX-COMPILER       % Specify which compiler to be used
%LATEX-COMPILE-COUNT:1:LATEX-COMPILE-COUNT      % How many iterations to make the compiler
\documentclass[paper=a4,fontsize=18pt]{article}
\usepackage{geometry}
\geometry{
% verbose,
portrait,       % page orientation (landscape or portrait)
a4paper,        % paper size
tmargin=5mm,    % page top margin
bmargin=5mm,    % page bottom margin
lmargin=5mm,   % page left margin
rmargin=5mm % page right maring
}

\usepackage[utf8]{inputenc}
\usepackage[defaultsans]{opensans} %font
\usepackage[T1, T2A]{fontenc}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{layouts}
\usepackage{xltabular}

\newcommand{\smf}{ % small font
\fontsize{9}{11}\selectfont
}

\begin{document}

% the table does not spread to \textwidth
\begin{xltabular}{\textwidth}{|X|X|X|}
% \multicolumn{1}{|c|}{very long content } & setting the widths & of each column \\ \kill
\multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} \\
\multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test}
\end{xltabular}

% table spread to \textwidth but without multicolumn
\begin{xltabular}{\textwidth}{|X|X|X|}
test & test & is test \\
test & test & test
\end{xltabular}

% table spread to \textwidth, works with multicolumn BUT gives error under TeX Live 2017
\begin{xltabular}{\textwidth}{|X|X|X|}
\multicolumn{1}{|c|}{test } & \multicolumn{1}{|c|}{test } & \multicolumn{1}{|c|}{test } \\ \kill
\multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} \\
\multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test}
\end{xltabular}

\end{document}

• If you are using lualatex you should not be using legacy encodings such with fontenc \usepackage[T1, T2A]{fontenc} Nor should use use imputenc: \usepackage[utf8]{inputenc} (this just makes a warning that it is not being used) (in the text you say you pdftex, the comment in the code says luatex) Feb 15 at 12:51
• using tabularx but removing every X column by replacing it with c in \multicolum can never do anything useful. Even if you avoid the low level tex error I would say that this is wrong input and not supported by design. Feb 15 at 12:56
• you still have \newcommand{\smf}{ % small font which makes every use of \smf add spurious white space, delete the space before % Feb 15 at 12:57
• Thank you for the corrections. Feb 15 at 13:06

Removing all the X columns from a tabularx means it can never do anything useful, even if you avoided the error. To center the the text in an X column use \centering not replace X by c.

 \documentclass[paper=a4,fontsize=18pt]{article}
\usepackage{geometry}
\geometry{
% verbose,
portrait,       % page orientation (landscape or portrait)
a4paper,        % paper size
tmargin=5mm,    % page top margin
bmargin=5mm,    % page bottom margin
lmargin=5mm,   % page left margin
rmargin=5mm % page right maring
}

\usepackage[utf8]{inputenc}
\usepackage[defaultsans]{opensans} %font
\usepackage[T1, T2A]{fontenc}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{layouts}
\usepackage{xltabular}

\newcommand{\smf}{ % small font
\fontsize{9}{11}\selectfont
}

\begin{document}

% the table does not spread to \textwidth
\begin{xltabular}{\textwidth}{|X|X|X|}
% \multicolumn{1}{|c|}{very long content } & setting the widths & of each column \\ \kill
\multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} \\
\multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test} & \multicolumn{1}{|c|}{test}
\end{xltabular}

% table spread to \textwidth but without multicolumn
\begin{xltabular}{\textwidth}{|X|X|X|}
test & test & is test \\
test & test & test
\end{xltabular}

% table spread to \textwidth, works with multicolumn BUT gives error under TeX Live 2017
\begin{xltabular}{\textwidth}{|*{3}{>{\centering\arraybackslash}X|}}
test & test & test \\
test & test & test \\
\end{xltabular}

\end{document}


this was processed with pdftex not luatex as you specified T1 and T2A encodings.

• In the last table there isn't a single multicolumn. In some tables I need to have at least 50 columns and use portions of them. Feb 15 at 13:27
• I think you are misusing tabularx, in any tabular (not just tabularx) you should not specify unused columns (as tex will remove the columns if you do not) so unless you really need a 50 column table then the markup is wrong. Feb 15 at 13:30
• What unused columns means exactly ? If I have 2 columns and a row with multicolumn{2} I am using them or I don't ? Feb 15 at 13:35
• @LubomirBorisov not if you span that in every row. In your example in the question you have \multicolumn in every cell so the original XXX is not used at all, you could have well had ccc or lll or anything so even though it looks like you have X columns they are not used at all. Feb 15 at 13:37
• I understand. It seems that there are things I don't know about latex so I am going to post my complete table on separate post and ask how to improve it. Thank you. Feb 16 at 7:26