
Como posso obter tikz
dimensões de nós, como altura e largura? Estou interessado em usar esses parâmetros para calcular com precisão o posicionamento de objetos, por exemplo, usando <a.height>
o exemplo a seguir:
\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}
Responder1
Dois exemplos onde o resultado desejado é obtido sem conhecer as dimensões do nó. O segundo usa 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}
Atualizar:
Suponhamos que queremos a etiqueta label without calc
2cm à direita e 1cm acima da sua posição real no exemplo anterior: \path (a.center)--(a.north) node[pos=.75, right] {label without calc}
. Podemos usar positioning
a biblioteca para mover o nó em relação ao ponto correspondente no caminho. Neste caso podemos dizer above right=1cm and 2cm
mas isso usará south west
âncora para posicionamento e queremos west
, então adicionamos anchor=west
após above right
a opção:
\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}