
이 코드
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{forest}
\begin{document}
We are the knights who say "Ni!".
\begin{center}
\begin{tikzpicture}[framed]
\begin{forest}
[,for tree={grow'=east},shape=coordinate
[
[
[]
[]
]
[
[]
[]
]
]
[
[
[]
[]
]
[
[]
[]
]
]
]
\end{forest}
\end{tikzpicture}
\end{center}
\end{document}
나에게 준다
분명히 나무는 그림의 경계를 벗어나서 위의 텍스트와 겹치게 됩니다. 이것은 알려진 버그입니까 아니면 제 실수입니까? 수정 사항이 있습니까?
답변1
forest
환경을 내부에 두는 것은 전혀 좋은 생각이 아니라고 생각하며 tikzpicture
예기치 않게 나쁜 일이 발생할 수 있다고 강하게 의심합니다. 일반적으로 중첩은 tikzpicture
간단한 경우에는 작동하지만 문제가 있는 것으로 알려져 있습니다. (즉, 작동하면 작동하고, 작동하지 않으면 두 부분을 모두 유지해야 합니다.) a는 forest
a tikzpicture
이므로 본질적으로 다음과 같이 말하고 있음 을 기억하세요.
\begin{tikzpicture}[framed]
...
\begin{tikzpicture}
...
baseline
예를 들어, 그림을 적절하게 조정하면 제대로 작동합니다 .
\begin{tikzpicture}[framed,baseline=(current bounding box.center)]
하지만 프레임을 의 일부로 그리는 것이 더 안전할 것이라고 생각합니다 forest
. 나는 당신이 결국 단순한 상자보다 더 멋진 것을 갖고 싶어한다고 생각합니다. 그렇지 않은 경우 더 간단한 접근 방식이 있습니다. 그러나 사양 자체의 일부로 복잡한 배경을 쉽게 추가할 수 있습니다 forest
. 이를 수행하는 방법에는 여러 가지가 있습니다.
\begin{forest}
[
..
]
\begin{scope}[on background layer]
<drawing commands>
\end{scope}
\end{forest}
또는 그리기 명령을 트리 사양의 일부로 또는 트리 프리앰블에 추가할 수 있습니다. 예를 들어,
\begin{forest}
[,for tree={grow'=east},shape=coordinate, tikz+={%
\begin{scope}[on background layer]
\node [fit=(current bounding box.north east) (current bounding box.south west), draw=blue!50!cyan, outer color=blue!50!cyan!25, inner color=blue!50!cyan!10, rounded corners, line width=1mm] {};
\end{scope}
}
[
...
\end{forest}
예제의 전체 코드:
\documentclass[a4paper]{article}
\usepackage{forest}
\usetikzlibrary{backgrounds,fit}
\begin{document}
We are the knights who say "Ni!".
\begin{center}
\begin{tikzpicture}[framed,baseline=(current bounding box.center)]
\begin{forest}
[,for tree={grow'=east},shape=coordinate
[
[
[]
[]
]
[
[]
[]
]
]
[
[
[]
[]
]
[
[]
[]
]
]
]
\end{forest}
\end{tikzpicture}
\end{center}
We are the knights who say "Ni!".
\begin{center}
\begin{forest}
[,for tree={grow'=east},shape=coordinate, tikz+={%
\begin{scope}[on background layer]
\node [fit=(current bounding box.north east) (current bounding box.south west), draw=blue!50!cyan, outer color=blue!50!cyan!25, inner color=blue!50!cyan!10, rounded corners, line width=1mm] {};
\end{scope}
}
[
[
[]
[]
]
[
[]
[]
]
]
[
[
[]
[]
]
[
[]
[]
]
]
]
\end{forest}
\end{center}
\end{document}