2

I am creating TikZ pictures using some external images in the following manner:

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{figure}[htb]
    \centering\small
    \begin{tikzpicture}
        \coordinate (O) at (0,0,0);
        \pgfdeclareimage[width=2cm]{moon}{moon.png}
        \node (moonn) at (O) {\pgfbox[center,center]{\pgfuseimage{moon}}};
    \end{tikzpicture}
    \caption{This is a long caption. As you can see it interferes with the Moon!}
\end{figure}

\end{document}

The problem is that there does not seem to be a bounding box around the image, and it thus interferes with the caption:

Caption interference

How can I solve this problem? Am I using wrong code?


Appendix

Used image:

The Moon

Ingo
  • 20,035
  • 1
    You can (and indeed usually should) just use the normal \includegraphics command to insert an image in a node: \node (moon) at (O) {\includegraphics[width=2cm]{moon}}; works. Do you have a particular reason for using \pgfdeclareimage? – Jake Jun 27 '13 at 12:23
  • Thanks for your comment, Jake. Maybe I misread, but I understood from the question below that I have to "encapsulate the image by \pgfbox to be able to use it within a node". Source: http://tex.stackexchange.com/questions/2152/tikz-using-external-images-as-building-blocks – Ingo Jun 27 '13 at 13:11
  • There really is no reason to go that way. Check the comments under the answer, especially [http://tex.stackexchange.com/questions/2152/tikz-using-external-images-as-building-blocks#comment70409_2153] – Jake Jun 27 '13 at 13:15

1 Answers1

4

Putting the image reference into \pgfbox[center,center]{...} is the culprit. It creates a zero-size box with its content centred.

Just say:

\node (moon) at (O) {\pgfuseimage{moon}};
AlexG
  • 54,894