
Fiz uma matriz em uma apresentação de projetor e estou tentando estilizar os nós.
\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}
Das três linhas comentadas, a primeira funciona e as outras duas falham. Para a macro \foo eu recebo:
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.
Mas se eu colar o corpo da macro onde tentei usar, não tem problema. É claro que estou perdendo algo fundamental sobre macros, mas o quê?
Invocar \foo no tikzset deu o mesmo resultado.
O foreach me dá algo totalmente enigmático:
! Undefined control sequence.
\foreach ...reach \let \pgffor@assign@before@code
=\pgfutil@empty \let \pgff...
Qualquer ajuda muito apreciada.
Responder1
Eu não acho que você possa usar macros nesse sentido, mas você pode simplesmente definir um novo estilo, ou seja
\tikzset{foo/.style={row #1/.style={inuse}}}
Com essa definição, adicione foo=1
para adicionar o inuse
estilo à linha 1, foo=2
à linha 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}