tikz 節點的中心

tikz 節點的中心

以下程式碼來自 @domenico-camasta

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{figure}
    \begin{tikzpicture}
    \node(a){\includegraphics[width=0.8\textwidth]{example-image-a}};
    \node at (a.north east)
    [
    anchor=center,
    xshift=0mm,
    yshift=0mm
    ]
    {
        \includegraphics[width=0.3\textwidth]{example-image-b}
    };
    \end{tikzpicture}
\end{figure}

\end{document}

產生以下結果 在此輸入影像描述

也可以看看在一篇文章中疊加兩個圖像

我需要怎樣重寫

a.north east

在上面的例子中,如果我想放置圖像 B:

1)在圖像A的中心

2)在圖像A的中心東邊?

答案1

看第72章tikz 和 pgf 手冊關於shape圖書館。在那裡,您將找到一個節點形狀列表,並且每​​個節點形狀都會顯示一個帶有預定義錨點的圖表,與預設形狀類似rectangle

在此輸入影像描述

(請注意,10130錨點只是範例,您可以使用 0 到 360 之間的任何度數。)

因此,您需要的是centereast錨點,如下面的程式碼所示。

另請注意,您可能希望inner sep=0a節點進行設置,以刪除節點內容和邊框之間的「填充」。

在此輸入影像描述

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{figure}
    \begin{tikzpicture}
    \node [inner sep=0] (a){\includegraphics[width=0.8\textwidth]{example-image}};
    \node at (a.north east)
    [
    anchor=center,
    xshift=0mm,
    yshift=0mm
    ]
    {
        \includegraphics[width=0.3\textwidth]{example-image-a}
    };
    \node at (a.center) {\includegraphics[width=0.3\textwidth]{example-image-b}};
    \node at (a.east) {\includegraphics[width=0.3\textwidth]{example-image-c}};
    \end{tikzpicture}
\end{figure}

\end{document}

答案2

預設定位為 using center,預設錨點為center,因此只需node at (a)將節點放置在a.center。因此,中東地點正好east

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{figure}
    \begin{tikzpicture}
    \node(a)[inner sep=0pt]{\includegraphics[width=0.8\textwidth]{example-image-a}};
    \node at (a)
    {
        \includegraphics[width=0.3\textwidth]{example-image-b}
    }
    node at (a.east)
    {
        \includegraphics[width=0.3\textwidth]{example-image-b}
    };
    \end{tikzpicture}
\end{figure}

\end{document}

在此輸入影像描述

相關內容