4

I'm trying to create tables with many columns and many empty fields. I'd like to reference the fields later as TikZ nodes to add more TikZ stuff around them, so \matrix{} looked like a good idea. I tried to use \newcommand{\myrow}[number of columns]{row content goes here} to seperate row content and layout, but ran into the nine-argument-limit of \newcommand, so I tried a key-value interface to add more columns. Trouble with that is, all key-value frameworks I tried (keyval, pgfkeys,keycommand) are thrown off by the column delimiter of the first column, be it &, \& or \pgfmatrixnextcell: From the second column on, the cells are either empty, contain \myrow's keys instead of their values, or make pdflatex error out with "undefined control sequence", depending on the combination of tools used. What all these cases have in common, is that only the first column contains the desired content. This holds true not only for \matrix{}, but also for tabular environments.

To exemplify, I use the keycommand interface and a tabular, because that's the shortest combination:

\documentclass{standalone}
\usepackage{keycommand}

\newkeycommand{\myrow}[keyA=defaultA, keyB=defaultB]{%
  \commandkey{keyA} & \commandkey{keyB} \\
}

\begin{document}
\begin{tabular}[t]{ll}
  \myrow[keyA=this, keyB=that]
  \myrow[keyA=see,  keyB=me]
\end{tabular}
\end{document}

Which gives:

enter image description here

I would be grateful for an explanation of what's going on and how to get past this. The example only shows what I consider my root problem, but please keep in mind that suggestions should also be compatible with a TikZ matrix of nodes.

1

FWIW, I've ended up giving up on \matrix{} and use handmade positioning:

\documentclass{standalone}
\usepackage{keycommand}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\newkeycommand{\myrow}[keyA=defaultA, keyB=defaultB, keyC=defaultC]{%
  \node (A) at ($(0,  0) - (pos)$)  [anchor=east]{\commandkey{keyA}};
  \node (B) at ($(4,  0) - (pos)$)  [anchor=west]{\commandkey{keyB}};
  \node (C) at ($(40, 0) - (pos)$)  [anchor=west]{\commandkey{keyC}};
  \coordinate (pos) at ($(pos) + (0, 18)$);
}

\begin{document}
  \begin{tikzpicture}[node distance=0cm,inner xsep=0pt,x=1pt,y=1pt]
    \tikzstyle{every node}+=[text height=0.6em,text depth=0.1em]
    \coordinate (pos) at (0, 0);
    \myrow[keyA=this, keyB=that]
    \myrow[keyA=see,  keyB=me]
  \end{tikzpicture}
\end{document}

enter image description here

It works with many key-value-pairs. I've tried 18.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.