
rectangle split
노드 모양을 설정하고 스타일에 의해 정의된 콘텐츠가 포함된 첫 번째 부분을 자동으로 추가하는 TikZ 노드 스타일을 정의하고 싶습니다 . 일반적인 노드 텍스트는 두 번째 부분에 나타납니다. 이 작업을 수행하는 방법이나 이와 유사한 방법이 있습니까?
원하는 동작
암호:
\node[achtung] at (1, 2) {Falling rocks};
산출:
( Achtung | Falling rocks )
시도
난 노력 했어
achtung/.append style={
execute at begin node={Achtung\nodepart{two}},
rectangle split,
rectangle split horizontal,
rectangle split parts=2
}
그리고 좀 더 정교한 버전,
achtung/.append style={
execute at begin node={Achtung\protect\nodepart{two}\protect\begingroup},
execute at end node={\protect\endgroup},
rectangle split,
rectangle split horizontal,
rectangle split parts=2,
every one node part/.style={
execute at begin node={},
execute at end node={}
},
every two node part/.style={
execute at begin node={},
execute at end node={}
}
}
모두 "Extra }, or forgotten \\endgroup.\n\\pgfutil@reserved@c ->\\egroup \n"
오류가 발생합니다.
컴파일을 사용하는 버전 \pgfnodeparttwobox
이지만 원하는 동작을 제공하지 않습니다.
최소한의 작동하지 않는 예
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\tikzset{
achtung/.append style={
execute at begin node={Achtung\nodepart{two}}, % remove this line to compile successfully
rectangle split,
rectangle split horizontal,
rectangle split parts=2,
draw
}
}
\begin{document}
\begin{tikzpicture}
\node[achtung] {Falling rocks};
\end{tikzpicture}
\end{document}
답변1
execute at begin node
노드 부분을 가지고 놀기에는 후크가 너무 이르습니다. 여기서는 실제로 사용할 적절한 후크가 없습니다. 시작 시 바로 실행될 다른 매크로 중 하나를 오용하려고 시도할 수 있습니다. 이 매크로는 수평 정렬 및 중첩된 TikZ 그림(?)을 처리합니다.
그러나 그것들을 어지럽히고 비호환성을 만드는 대신 print at begin node
에 유사하게 작동 node contents
하지만 대체하는 대신에 {
와 사이에 오는 것을 접두사로 붙이는 우리만의 후크를 추가하겠습니다 }
.
(이 후크는~ 아니다TikZ 사진이 노드 콘텐츠의 일부인 경우 재설정되지만 처음부터 그렇게 하는 것은 좋은 생각이 아닙니다.)
암호
\documentclass[tikz]{standalone}
%\documentclass{article}
%\usepackage{tikz}
\ExplSyntaxOn \makeatletter
\tl_replace_once:Nnn \tikz@do@fig
{ \ignorespaces }
{ \pgfkeysvalueof{/tikz/print~at~begin~node} \ignorespaces }
\makeatother \ExplSyntaxOff
\pgfkeyssetvalue{/tikz/print at begin node}{}
\usetikzlibrary{shapes.multipart}
\tikzset{
achtung/.append style={
print at begin node = Achtung \nodepart{two},
rectangle split, rectangle split horizontal, rectangle split parts=2, draw}}
\tikzset{
gnutcha/.append style={
print at begin node = \nodepart{two} Achtung \nodepart{one},
rectangle split, rectangle split horizontal, rectangle split parts=2, draw}}
\begin{document}
\tikz \node[achtung] {Falling rocks}
node[gnutcha] at (0, -1) {Falling rocks};
\tikz \node[achtung] {Falling rocks \nodepart{text} You're not the }
node[achtung] at (0, -1) {Falling rocks \nodepart{one} boss of me. };
\end{document}
산출
답변2
를 사용하면 스타일을 node contents
가질 수 있고 . 의견에서 언급했듯이 using 은 할 수 없지만 작동한다는 의미 입니다.node contents={Achtung\nodepart{two}#1}
achtung={Falling rocks}
node contents
\node [..] at (x,y)...
\node at (x,y) [...]
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\tikzset{
achtung/.append style={
rectangle split,
rectangle split horizontal,
rectangle split parts=2,
draw,
node contents={Achtung\nodepart{two}#1}
},
achtung/.default=
}
\begin{document}
\begin{tikzpicture}
\node[achtung={Falling rocks}];
\end{tikzpicture}
\end{document}
답변3
명령으로?
편집: Alan Munn의 의견을 사용하여 노드의 위치를 매개변수로 추가하고 D(){}
#2 매개변수에 대한 사양을 추가합니다.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\NewDocumentCommand{\mynode}{ O{achtung} d() m }{
\IfNoValueTF{#2}
{\path node[#1,right]{#1\nodepart{two}#3};}
{\path (#2) node[#1,right]{#1\nodepart{two}#3};}
}
\tikzset{
achtung/.style={
rectangle split,
rectangle split horizontal,
rectangle split parts=2,
draw,
}
}
\begin{document}
\begin{tikzpicture}
\draw[help lines](0,0)grid(3,2);
\mynode[achtung] (2,1) {Falling rocks}
\mynode (0,0) {achtung is the default style}
\end{tikzpicture}
\end{document}