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

3
  • 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, 2013 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: tex.stackexchange.com/questions/2152/…
    – Ingo
    Jun 27, 2013 at 13:11
  • There really is no reason to go that way. Check the comments under the answer, especially [tex.stackexchange.com/questions/2152/…
    – Jake
    Jun 27, 2013 at 13:15

1 Answer 1

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}};
0

You must log in to answer this question.

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