使用tikz對圖片進行註解;裝飾在超過一定圖片寬度後消失?

使用tikz對圖片進行註解;裝飾在超過一定圖片寬度後消失?

我正在嘗試使用 tikz 註釋圖片。不知怎的,雖然有些我不理解的行為。我在註解線的末端畫了一個不超過一個圓圈的裝飾。裝飾是透過 a 來定義的tikzset。到目前為止沒有什麼特別的。然而,當我嘗試對給定寬度超過 7 厘米的圖片進行註釋時,有些東西會導致裝飾消失。這是我正在談論的(希望是最小的)MWE,在 Overleaf 中進行了測試:

\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仍然被繪製。在第二張圖片中,寬度設定為 8 公分(唯一的差異),不再繪製圓圈。

我真的很想了解為什麼會發生這種情況以及如何避免/修復它。

答案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}

這使: 在此輸入影像描述

相關內容