I need an environment that presents data in a table. The number of right-most columns shall be adjusted at compile-time, and the first column is dynamic width. For this reason I am using \usepackage{tabularx}
. However, when I add \usepackage{csquotes}
to the list of packages, I get the following error:
Misplaced \noalign. (in macro \hline)
To illustrate this problem, consider the MWE below:
\documentclass{article}
\usepackage{latexsym} % for \Box
\usepackage{tabularx}
\usepackage{multicol} % for headings
% \usepackage{csquotes} % Uncomment and won't work anymore
\newcommand{\extracols}{5}
\newenvironment{mydyntable}{%
\newcommand{\extraheadings}[1]{% Autogenerated
$1^{st}$&$2^{nd}$&$3^{rd}$&$4^{th}$&$5^{th}$%
}
\newcommand{\myheading}[1]{%
\xdef\colspan{\the\numexpr2+\extracols\relax}%
\phantom{.} \\[-2em]\multicolumn{\colspan}{X}{\textbf{##1}}\\
}
\newcommand{\myrecord}[2]{% Also autogenerated
##1&##2&$\Box$&$\Box$&$\Box$&$\Box$&$\Box$\\
}
\tabularx{\textwidth}{ X r *{\extracols}{c}}
\textbf{First} & \textbf{Second} & \extraheadings{\extracols}
\\\hline
}{% \end{mydyntable}
\hline\\ %Breaks here!!!!!
\endtabularx
}
\begin{document}
\begin{mydyntable}
\myheading{Fuuu}
\myrecord{Hello}{World}
\end{mydyntable}
\end{document}
The trivial solution is document that the solution is not compatible with csquotes, but because of reasons both might (and will) be used altogether. Further, most probably the solution will be exported as package, so I'd also like to reduce dependencies on external packages to a minimum. Solutions I've checked include [1], [2], [3], and [4].
Already tried with environ's NewEnviron
but didn't work. Also got bad results with \usepackage{tabu}
.
A workaround, as the title suggests, is replacing tabularx
with tabular*
, but then the width of the first column becomes problematic. I would need to make some calculations on the size of each additional column on the right (all about the same size), the two first columns, and the width of the text/line. More or less like this:
\newcommand{\fcwidth}{\linewidth - (
\widthof{\secondColumnCaption} +
\extracols * \widthof{\extraColAvgWidth})
}
So far I've tried with \the\numexpr...\relax
and the package \usepackage{calc}
but with little to no success, and I ran out of ideas. If it helps, for the final implementation I'm using pgfkeys
and pgffor
to allow key-value customization of the captions and other stuff inside the environment, but my experience with tiks/pgf is close to null.
To get rid of the error I know I can use \tabularnewline
but I don't know how to solve the \hline
problem and if those hacks won't cause further incompatibility.
Any suggestion is appreciated.
Edit 1:
As @moewe pointed out in the comments, the error also occurs with etoolbox
The following MWE is even more minimal and still reproduces the issue
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tabularx}
\newenvironment{mydyntable}
{\tabularx{\textwidth}{c}}
{\\\hline\endtabularx}
\begin{document}
\begin{mydyntable}
\end{mydyntable}
\end{document}
etoolbox
instead ofcsquotes
.etoolbox
. Edited.\AtEndEnvironment
inetoolbox
. If the relevant\patchcmd\end
is removed frometoolbox
everything works fine.