
나는 비머 프리젠테이션에서 행렬을 만들었고 노드의 스타일을 지정하려고 합니다.
\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}
주석 처리된 세 줄 중 첫 번째는 작동하고 나머지 두 줄은 실패합니다. \foo 매크로의 경우 다음을 얻습니다.
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.
하지만 제가 사용하려고 했던 곳에 매크로 본체를 붙이면 문제 없습니다. 분명히 매크로에 대한 근본적인 것을 놓치고 있습니다. 하지만 무엇입니까?
tikzset에서 \foo를 호출하면 동일한 결과가 나타납니다.
foreach는 나에게 완전히 비밀스러운 것을 제공합니다.
! Undefined control sequence.
\foreach ...reach \let \pgffor@assign@before@code
=\pgfutil@empty \let \pgff...
도움을 주시면 감사하겠습니다.
답변1
그런 의미에서 매크로를 사용할 수는 없을 것 같지만 대신에 새로운 스타일을 정의할 수 있습니다.
\tikzset{foo/.style={row #1/.style={inuse}}}
해당 정의를 사용하여 행 1, 행 2 등에 스타일을 foo=1
추가하려면 추가하세요.inuse
foo=2
\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}