I want to use a TikZ matrix to draw a table with empty cells. But no matter what I do I run into errors. In particular, LaTeX complains about
! Package pgf Error: No shape named ae-5-4 is known.
Here's the code (far from what I really want):
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[
%%---------------------------------------
dm/.style={decoration={brace,mirror},decorate},
dd/.style={decoration={brace},decorate},
%%---------------------------------------
nlble/.style={inner sep=0pt,anchor=east},
nlblw/.style={inner sep=0pt,anchor=west},
%%---------------------------------------
]
\matrix (ae) [matrix of nodes,
column 1/.style={anchor=west},
minimum width=2cm,
column sep=2.5ex,
row sep=2.5ex,
matrix of nodes/.style={execute at empty cell=\node {AAA};}
]
{
& column A & column B & column C & g \\
Row A & & & & a \node (cc) {}; \\
Row B & & & & \node (ss) {}; \\
Row C & & & & \node (alt) {}; \\
Row D & & & & \\
};
\foreach \row in {1,2,3,4,5} {%
\draw[blue,line width=0.4pt] ($(ae-\row-2.base west)-(0,2ex)$) -- ($(ae-\row-4.base east)-(0,2ex)$);
}
% \foreach \col in {1,2,3,4}{%
% \draw[blue,line width=0.4pt] ($(ae-1-\col.base east)-(0,2ex)$) -- ($(ae-4-\col.base east)-(0,2ex)$);
% }
\draw[dm] ($(ae-2-1.west)+(0,2.5ex)$) -- ($(ae-3-1.west)-(0,2.5ex)$) node [midway,anchor=east] (A) {};
\draw[dm] ($(ae-4-1.west)+(0,2.5ex)$) -- ($(ae-4-1.west)-(0,2.5ex)$) node [midway,anchor=east] (B) {};
\draw[dd] ($(cc.east)+(0,2.5ex)$) -- ($(cc.east)+(0,-2.5ex)$) node [midway,anchor=west] (C) {};
\draw[dd] ($(ss.east)+(0,2.5ex)$) -- ($(alt.east)+(0,-2.5ex)$) node [midway,anchor=west] (D) {};
\node[nlble] at ($(A)+(-1ex,0)$) {\parbox{1.35in}{\footnotesize\centering Instructions for material to be put in Rows A and B.}};
\node[nlble] at ($(B)+(-1ex,0)$) {\parbox{1.35in}{\footnotesize\centering Instructions for material to be put in Row C.}};
\node[nlblw] at ($(C)+(1ex,0)$) {\parbox{1.5in}{\footnotesize\centering Additional instructions for Row A.}};
\node[nlblw] at ($(D)+(1ex,0)$) {\parbox{1.5in}{\footnotesize\centering Additional instructions for Rows B and C.}};
\end{tikzpicture}
\end{document}
What I'm most interested in knowing is how to automate drawing horizontal and vertical lines. I'd prefer to do it using the node names that TikZ creates for the cells of a matrix.
Of secondary interest,
- I would like to know why when I try to add text before the
\node {cc};
in the last column ofRow A
, I get anundefined command
error from LaTeX. - I would also like to know whether there's a way to define the style for a range of columns (such as columns 2, 3, and 4) without having to declare the style for each individual column or define a style universally for all columns. For example, I only want to set the
minimum width
for columns 1, 2, and 3.