
Hice una matriz en una presentación de proyector y estoy tratando de diseñar los nodos.
\newcommand\foo{row 1/.style={inuse}}
\begin{frame}{Chunks}
\tikzset{
inuse/.style={text=red},
free/.style={text=green},
addr/.style={minimum width=3em},
data/.style={nodes=draw,minimum width=6em},
}
\scalebox{0.6}{
\begin{tikzpicture}[node distance=2mm]
\matrix(magic) [matrix of nodes,ampersand replacement=\&,row sep=-\pgflinewidth,
column 1/.style={addr},
column 2/.style={data, column sep=1em},
%row 1 column 2/.style={inuse},
%\foo ,
%\foreach \r in { 1,2,3 } {row \r column 2/.style={inuse}, }
column 3/.style={addr},
column 4/.style={free, data, column sep=1em},
]
{
100: \& 00000010 \& 110: \& 12345678 \& 120: \& 12345678 \& 130: \& 12345678 \\
101: \& 00000001 \& 111: \& 12345678 \& 121: \& 12345678 \& 131: \& 12345678 \\
102: \& 00000002 \& 112: \& 12345678 \& 122: \& 12345678 \& 132: \& 12345678 \\
103: \& 00000003 \& 113: \& 12345678 \& 123: \& 12345678 \& 133: \& 12345678 \\
};
\end{tikzpicture}
}
\end{frame}
De las tres líneas comentadas, la primera funciona y las otras dos fracasan. Para la macro \foo obtengo:
Package pgfkeys Error: I do not know the key '/tikz/row 1/.style={inuse}' and
I am going to ignore it. Perhaps you misspelled it.
Pero si pego el cuerpo de la macro donde intenté usarlo, no hay problema. Claramente me falta algo fundamental sobre las macros, pero ¿qué?
Invocar \foo en el tikzset dio el mismo resultado.
El foreach me da algo totalmente críptico:
! Undefined control sequence.
\foreach ...reach \let \pgffor@assign@before@code
=\pgfutil@empty \let \pgff...
Cualquier ayuda muy apreciada.
Respuesta1
No creo que puedas usar macros en ese sentido, pero en su lugar puedes definir un nuevo estilo, es decir
\tikzset{foo/.style={row #1/.style={inuse}}}
Con esa definición, agregue foo=1
para agregar el inuse
estilo a la fila 1, foo=2
para la fila 2, etc.
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{foo/.style={row #1/.style={inuse}}}
\begin{document}
\begin{frame}{Chunks}
\tikzset{
inuse/.style={text=red},
free/.style={text=green},
addr/.style={minimum width=3em},
data/.style={nodes=draw,minimum width=6em},
}
\scalebox{0.6}{
\begin{tikzpicture}[node distance=2mm]
\matrix(magic) [matrix of nodes,ampersand replacement=\&,row sep=-\pgflinewidth,
column 1/.style={addr},
column 2/.style={data, column sep=1em},
foo=1,
column 3/.style={addr},
column 4/.style={free, data, column sep=1em},
]
{
100: \& 00000010 \& 110: \& 12345678 \& 120: \& 12345678 \& 130: \& 12345678 \\
101: \& 00000001 \& 111: \& 12345678 \& 121: \& 12345678 \& 131: \& 12345678 \\
102: \& 00000002 \& 112: \& 12345678 \& 122: \& 12345678 \& 132: \& 12345678 \\
103: \& 00000003 \& 113: \& 12345678 \& 123: \& 12345678 \& 133: \& 12345678 \\
};
\end{tikzpicture}
}
\end{frame}
\end{document}