I'm currently figuring out how to use pgfkeys, and I'm running into the following problem. I'm trying to define a command that prints part of a table, filled with arguments provided through pgfkeys. A simplified version of my situation looks like this:
\documentclass{article}
\usepackage{pgfkeys,xparse}
\pgfkeys{
/test/.is family, /test,
right/.estore in=\testright,
left/.estore in=\testleft,
}
\NewDocumentCommand{\tablepart}{o}{
\pgfkeys{/test,#1}
\testleft{} & \testright{} \
\testleft{} & \testright{} \
}
\begin{document}
\begin{tabular}{rl}
\tablepart[left={ABC},right={DEF}]{}
\end{tabular}
\end{document}
However, this setup gives me an Undefined control sequence error on \tablepart[left={ABC},right={DEF}]{}. If I remove the ampersand and \\ in the definition of \tablerow, however, the error disappears. What am I doing wrong here?
tabularusage into your\tablepartmacro so that you set the values outside of thetabularenvironment. That way, the will all be accessoble. What are you trying to achieve?\NewDocumentCommand{\tablepart}{o}{\begingroup\pgfqkeys{/test}{#1}\begin{tabular}{rl}\testleft&\testright\\\testleft&\testright\\\end{tabular}\endgroup}– Qrrbrbirlbel Aug 19 '22 at 18:39\newcommand*\addtomacro[2]{\expandafter\def\expandafter#2\expandafter{#2#1}}\NewDocumentCommand{\tablepart}{o}{\pgfqkeys{/test}{#1}\def\mymacro{}\expandafter\addtomacro\expandafter{\testleft&}{\mymacro}\expandafter\addtomacro\expandafter{\testright\\}{\mymacro}\mymacro}You basically build the row and put it (including&and\\) in a macro and use it at the end. Though, I feel there are so many table package for LaTeX that there might be already a solution for your problem. – Qrrbrbirlbel Aug 19 '22 at 18:50