.png)
관련된:"명령 뒤에 추가" 및 "경로 삽입" 문제, 그러나 제 경우에는 솔루션을 적용하는 방법을 이해하지 못했습니다.
나는 다음을 사용하는 간단한 tikz 스타일을 정의하고 있습니다 append after command
.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[
fit after/.style={
append after command={%
node[draw, inner sep=0pt, fit=(\tikzlastnode)] {}
}
}
]
\node[fit after] {A};%%%% WORKS
\node {B} child { node[fit after] {C} }; %%%% FAILS
\end{tikzpicture}
\end{document}
첫 번째 노드( A
)에서는 잘 작동하고 주위에 직사각형을 그립니다.
그러나 노드 에서는 C
다음과 같은 오류 메시지가 나타납니다.
Package pgf Error: No shape named is known.
\tikzlastnode
이 경우 노드 이름을 하드코딩하는 것조차 여전히 실패하므로 이는 잘못이 아닙니다 child
.
경로 child
작업이 엉망입니까 append after command
? 해결 방법이 있나요?
triangle fit whole subtree
컨텍스트: 하위 트리의 모든 노드 주위에 맞는 삼각형을 그리는 명령을 만들려고 합니다 .
답변1
forest
옵션인 경우 fit whole subtree
스타일을 정의하는 것이 합리적으로 간단합니다. 삼각형 모양은 추천하지 않습니다. 조금 실험해 보았지만 필연적으로 매우 추악해 보였습니다. 그러나 fit whole subtree
노드 스타일을 지정하려는 옵션은 무엇이든 전달할 수 있습니다. 기본적으로 빨간색으로 직사각형을 그립니다.
중첩된 사용을 포함하여 을 여러 번 사용하면 fit whole subtree
문제 없이 작동합니다.
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\usetikzlibrary{fit}
\begin{document}
\newcommand*\makenodename[1]{(#1)}
\forestset{
declare toks={fit these}{},
fit whole subtree/.style={
delay={
temptoksa=,
for tree={%
temptoksa+/.wrap pgfmath arg={ (##1)}{name()},
},
fit these/.register=temptoksa,
delay={
tikz+={
\node [draw=red, fit=\foresteoption{fit these}, inner sep=0pt, #1] {};
},
},
},
},
}
\begin{forest}
for tree={
fit=band,
child anchor=parent,
parent anchor=children,
}
[A
[B
[C, fit whole subtree
[D]
[E
[X]
[Y
[Z]
]
]
[F]
[G]
]
[H
[I
[J]
[K]
[L]
]
]
]
[M, fit whole subtree={thick, draw=blue, rounded corners}
[N
[O
[R]
]
[P]
[Q]
]
[S, fit whole subtree={green, densely dashed, rounded corners}
[T]
[U]
[V]
[W]
]
]
]
\end{forest}
\end{document}