我正在尝试使用 tikz 注释图片。但不知何故,有些行为我不明白。我在注释行的末尾画了一个装饰,它只是一个圆圈。装饰通过 来定义tikzset
。到目前为止没有什么特别的。但是,当我尝试注释给定宽度超过 7 厘米的图片时,会出现某种情况导致装饰消失。以下是我在 Overleaf 中测试的(希望是最低限度的)MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{
o/.style={
shorten >=#1,
decoration = {
markings,
mark={
at position 1
with {
\draw circle [radius=#1];
}
}
},
postaction = decorate,
},
o/.default=2pt
}
\begin{document}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0,0){
\includegraphics[width=7cm]{frog} %%% works with a picture width of 7cm
};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[o,>=stealth,shorten <= 2mm, line width=0.5mm] (-0.25,1.25) node {Frog} to[out=-90] (0.41,0.6);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0,0){
\includegraphics[width=8cm]{frog} %%% circle vanishes with a picture width of 8cm
};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[o,>=stealth,shorten <= 2mm, line width=0.5mm] (-0.25,1.25) node {Frog} to[out=-90] (0.41,0.6);
\end{scope}
\end{tikzpicture}
\end{document}
第一张图片的宽度设置为 7cm。那里的圆圈仍然画在末端\draw
。第二张图片的宽度设置为 8cm(唯一的区别),圆圈不再画出来。
我真的很想了解为什么会发生这种情况以及如何避免/修复它。
答案1
我无法在任何大小的图像中获得线末端的圆圈。我没有检查原因,而是编写了新的、在我看来更简单的线条代码,它指向图像中的青蛙。在其中我使用了两个库:arrows.meta
用于线末端的圆圈和positioning
用于确定线坐标:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\tikzset{line/.style={-{Circle[open,length=#1]},shorten <= 2mm, line width=0.5mm},
line/.default=5pt}
\begin{document}
\begin{tikzpicture}
\node[anchor=north west,inner sep=0] (image) at (0,0,0){
\includegraphics[width=3cm]{example-image-a}};
\coordinate[above left=0.25 and 1.25 of image] (a);
\coordinate[above left=0.25 and 1.25 of image.center] (b);
\draw[line] (a) node {Frog} to[out=-90] (b);
\end{tikzpicture}
\bigskip
\begin{tikzpicture}
\node[anchor=north west,inner sep=0] (image) at (0,0,0){
\includegraphics[width=8cm]{example-image-b}};
\coordinate[above left=0.25 and 1.25 of image] (a);
\coordinate[above left=0.60 and 0.41 of image.center] (b);
\draw[line] (a) node {Frog} to[out=-90] (b);
\end{tikzpicture}
\end{document}