In the following example why is the column declaration troublesome
through the xkeyval macro, yet not via an argument declaration?
I'm afraid this has to do with expansion or so... and then I have no
idea how to correct that!
Can you help me please?
Best regards,
Mathieu
\documentclass{article}
\usepackage[latin1]{inputenc}% LaTeX source encoding
\usepackage[T1]{fontenc}% Font encoding
\usepackage{caption,floatrow,booktabs,array,longtable,multirow,tabularx}%
Tools for tables
\usepackage{xkeyval,lipsum}
\begin{filecontents}{File.tex}
\toprule
\textbf{Column A}
&\textbf{Column B}
&\centering \textbf{Column C}
\tabularnewline
\midrule
Cell A1
&Cell B1
&Cell C1\newline\lipsum[2]
\tabularnewline
Cell A2
&Cell B2
&Cell C2\newline\lipsum[2]
\tabularnewline
\bottomrule
\end{filecontents}
\begin{document}
\makeatletter%
\define@cmdkeys[MG]{table}{%
,defcolumns%
}%
\presetkeys[MG]{table}{%
,defcolumns={}%
}{}%
\newcommand*{\InsTab}[2]{%
\setkeys[MG]{table}{#1}%
\floatsetup[tmpset]{capposition=top}%
\begin{table}%
\floatbox[\nocapbeside]{table}[\textwidth]%
{\caption{\lipsum[2]}\label{table-label}}%
{%
\begin{tabularx}{\textwidth}{\cmdMG@table@defcolumns}%
% \begin{tabularx}{\textwidth}{#2}%
\@@input File.tex%
\end{tabularx}%
}%
\end{table}%
}%
\makeatother%
\InsTab{defcolumns=ccX}{ccX}
\end{document}
Expansion is the issue. The easiest approach here seems to be to ensure
that \cmdMG@table@defcolumns is expanded before
\begin{tabularx}{\textwidth} is looked at. So for example:
{\def\@tempa{\begin{tabularx}{\textwidth}}
\expandafter\@tempa\expandafter{\cmdMG@table@defcolumns}%
% \begin{tabularx}{\textwidth}{#2}%
\@@input File.tex%
\end{tabularx}%
}%
\end{table}%
}%
\makeatother%
\InsTab{defcolumns=ccX}{ccX}
\end{document}
--
Joseph Wright
> In the following example why is the column declaration troublesome
> through the xkeyval macro, yet not via an argument declaration?
> I'm afraid this has to do with expansion or so...
Yes, the column declaration must be given explicitely, not hidden
in a macro.
> \begin{tabularx}{\textwidth}{\cmdMG@table@defcolumns}%
\begingroup
\edef\process@me{\endgroup
\noexpand\begin{tabularx}{\noexpand\textwidth}%
{\cmdMG@table@defcolumns}%
}%
\process@me
* \edef expands, \noexpand prevent expansion inside \edef.
* The only purpose of the group is that the definition of
\process@me is thrown away after use. (Prevent name clashes.)
Yours sincerely
Heiko <ober...@uni-freiburg.de>