158

I want to embed an image within a tikzpicture environment. I tried the following,

\begin{tikzpicture}[]
  \pgftext{\includegraphics[width=150pt]{pic1.png}} at (0pt,0pt);
  \pgftext{\includegraphics[width=150pt]{pic2.png}} at (100pt,0);
\end{tikzpicture}

but both pictures are placed at upper-left corner of image, at the same position. I tried including them inside nodes as well, to no avail.

What am I doing wrong?

6

1 Answer 1

197

The prefered way to embed external pictures in a tikzpicture environment is to insert an \includegraphics{...} inside a \node. See the code below for an example.

enter image description here

\documentclass{article}

\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (russell) at (0,0)
    {\includegraphics[width=.25\textwidth]{bertrand_russell.jpg}};
\node[inner sep=0pt] (whitehead) at (5,-6)
    {\includegraphics[width=.25\textwidth]{alfred_north_whitehead.jpg}};
\draw[<->,thick] (russell.south east) -- (whitehead.north west)
    node[midway,fill=white] {Principia Mathematica};
\end{tikzpicture}
\end{document}

Links to the original pictures:

6
  • 2
    What's the use of the inner sep=0pt option?
    – nemarona
    Commented Feb 7, 2015 at 15:13
  • 5
    @nemarona Try to use inner sep=10pt (for example) and recompile. inner sep=0pt tells TikZ to make the node's bounding box as tight as possible around the image.
    – jub0bs
    Commented Feb 7, 2015 at 15:38
  • 11
    How do the image widths compare to the tikz coordinates? Commented Feb 17, 2016 at 16:25
  • There is some form to use mid north west o mid south east?. Thanks
    – LuisPac
    Commented Feb 22, 2018 at 13:51
  • Re. @ThomasAhle it's the normal one, see context - Setting unit length in TikZ? - TeX - LaTeX Stack Exchange (default is 1 unit = 1cm)
    – user202729
    Commented Apr 21, 2022 at 5:01

You must log in to answer this question.

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