tikzpicture 带描述框的居中图片

tikzpicture 带描述框的居中图片

我想将图片置于中心位置,并绘制一个箭头指向图片的一部分,以便放置带有说明的文本框。我想出了一个主意,就是将文本框和图片放在同一个“tikzpicture”下,但我的图片并没有像我想要的那样居中。

我所做的是:

\begin{figure}[H]
    \centering
    \begin{tikzpicture}% based on https://tex.stackexchange.com/a/9561/ (Caramdir's fantastic answer to another question)
    \node (map) [anchor=south west, inner sep=0pt] at (1.35,0.0) 
    {\fbox{\includegraphics[scale=.5]{photo/map.png}}};
    \node (box) [draw, rectangle] at (0.0,1.0) {Location};
    \begin{scope}[x={(map.south east)},y={(map.north west)}]
        \draw [->](box)--(.35,.4);
    \end{scope}
    \end{tikzpicture}
    \caption{Map}
    \label{fig:map}
\end{figure}

任何帮助都将不胜感激!

答案1

使用@leandriis 从他的评论中得到的想法和我对你的代码的一些小改动,同时考虑 Caramdir 的回答

\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}
\usepackage{graphicx}
\usepackage[skip=0.33\baselineskip]{caption}

\begin{document}
\begin{figure}[ht]
    \centering
\begin{tikzpicture}[node distance = 2mm]
    \node (map) [draw,
                 anchor=south west] % <--- https://tex.stackexchange.com/questions/9559/
                                    %   drawing-on-an-image-with-tikz)/9561#9561 (Caramdir)
                {\includegraphics[scale=.8]{example-image-duck}};
\begin{pgfinterruptboundingbox}% <--- proposed by @leandriis
    \node (box) [draw, left=of map] {Location};
        \begin{scope}[x={(map.south east)},y={(map.north west)}]
            \draw[-Straight Barb, semithick] (box) -- (0.5,0.35);
        \end{scope}
\end{pgfinterruptboundingbox}
    \end{tikzpicture}
\caption{Map}
\label{fig:map}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容