2

I would like to center a picture and draw an arrow to the part of the picture to have a text box with description. I have come up with an idea which is to put text box and picture under the same 'tikzpicture' but my picture doesn't go center that I want.

What I did is:

\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}

Any help is appreciated!

4
  • 1
    Using pgfinterruptedboundingbox as in \begin{pgfinterruptboundingbox} \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{pgfinterruptboundingbox} should solve this issue.
    – leandriis
    Commented Oct 8, 2020 at 8:47
  • @leandriis appreciated your help, it works!
    – Amos Tan
    Commented Oct 8, 2020 at 12:06
  • 1
    Welcome to TeX StackExchange! Commented Oct 8, 2020 at 12:20
  • @VeeHuaZhi Thank you for introducing, so good!
    – Amos Tan
    Commented Oct 8, 2020 at 12:24

1 Answer 1

1

Using @leandriis idea from his comment and some my small changes of your code, where consider also Caramdir's answer:

\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}

enter image description here

2
  • thank you for typing out the code, appreciated!
    – Amos Tan
    Commented Oct 8, 2020 at 12:07
  • @AmosTan, Thanks on this site are normally given via upvotes. You may not be aware of this.
    – Zarko
    Commented Oct 8, 2020 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .