
tikz
높이 및 너비와 같은 노드 크기를 어떻게 얻을 수 있나요 ? 나는 이 매개변수를 사용하여 객체의 배치를 정확하게 계산하는 데 관심이 있습니다. 예를 들어 <a.height>
다음 예에서는 다음을 사용합니다.
\documentclass{article}
\thispagestyle{empty}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\node(a) {
\includegraphics[width=0.8\textwidth]{example-image-a}
};
\node(b) at (0, <a.height>*3/4){label};
\end{tikzpicture}
\end{figure}
\end{document}
답변1
노드 크기를 모르고 원하는 결과를 얻은 두 가지 예입니다. 두 번째는 calc
tikzlibrary를 사용합니다.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node(a) {
\includegraphics[width=0.8\textwidth]{example-image-a}
};
\path (a.center)--(a.north) node[pos=.75, right] {label without calc};
\node[left] at ($(a.center)!.75!(a.north)$) {label with calc};
\end{tikzpicture}
\end{document}
업데이트:
label without calc
이전 예의 실제 위치에서 오른쪽으로 2cm, 위로 1cm 떨어진 라벨을 원한다고 가정해 보겠습니다 \path (a.center)--(a.north) node[pos=.75, right] {label without calc}
. 라이브러리를 사용하여 positioning
경로의 해당 지점을 기준으로 노드를 이동할 수 있습니다. 이 경우 우리는 배치를 위해 앵커를 above right=1cm and 2cm
사용할 것이라고 말할 수 있으며 우리는 원합니다. 그런 다음 옵션 뒤에 추가합니다 .south west
west
anchor=west
above right
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (a) {
\includegraphics[width=0.8\textwidth]{example-image-a}
};
\path (a.center)--(a.north) node[draw, pos=.75, above right=1cm and 2cm, anchor=west, red] (b) {label without calc};
\node[left] (c) at ($(a.center)!.75!(a.north)$) {label with calc};
%Some auxiliary elements.
\draw[red,<->] (a.center)--(c.east) node[midway, right] {75\%};
\draw[red,<->] (c.east)--(a.north) node[midway,right] {25\%};
\fill[red] (c.east) circle (1pt);
\draw[red,<->] (c.east)-|(b.west) node[pos=0.25,below] {2 cm} node[pos=0.75,left] {1 cm};
\end{tikzpicture}
\end{document}