
tikz を使用して画像に注釈を付けようとしています。しかし、なぜか理解できない動作があります。注釈ラインの末尾に、円以外の装飾を描画します。装飾は によって定義されますtikzset
。今のところ特別なことはありません。ただし、幅が 7cm を超える画像に注釈を付けようとすると、装飾が消えてしまう原因があります。以下は、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 に設定されている 2 番目の画像 (唯一の違い) では、円は描画されていません。
なぜこのようなことが起こるのか、またそれを回避/修正する方法を本当に理解したいと思います。
答え1
どのようなサイズの画像でも、線の端に円を表示できません。その理由は調べず、画像内のカエルを指し示す線用の、私見でははるかに簡単な新しいコードを書きました。その中で、arrows.meta
線の端に円を表示するためのライブラリと、positioning
線の座標を決定するためのライブラリの 2 つを使用します。
\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}