34

I want to create a simple figure where images are connected with arrows. Here is what I did:

\begin{tikzpicture}
\node[](A) {\includegraphics[width=0.2\textwidth]{a}};
\node[right=1mm of A](B) {\includegraphics[width=0.2\textwidth]{b}};
\draw[->] (A) to (B);
\end{tikzpicture}

example

But I want the arrow to start and end right at the images with no space between. How can I do that?

tauran
  • 585
  • 9
    add every node/.style={inner sep=0,outer sep=0} to the picture options – percusse Oct 04 '13 at 10:56
  • @percusse Would you like to write an answer, or is there a duplicate somewhere? – Torbjørn T. Oct 06 '13 at 15:10
  • @percusse / tauran: Would either of you like to write an answer? I thought I remembered a duplicate for this one but can't find it... – Paul Gessler Mar 02 '14 at 04:53
  • And every node/.style={inner xsep=0pt,outer xsep=0pt} for no sep. See Claudio Fiandrino: https://tex.stackexchange.com/questions/95649/reduce-white-space-around-tikz-picture – PatrickT Nov 29 '18 at 19:36

1 Answers1

52

The extra space is added according to the inner sep and outer sep amounts. If you zero them out the image is tightly packed inside the node thanks to inner sep=0 and moreover the arrows start right from the border thanks to outer sep=0

\documentclass[tikz]{standalone}
\usepackage{mwe} % For dummy images 
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}]
\node[](A) {\includegraphics[width=0.2\textwidth]{example-image-a}};
\node[right=1cm of A](B) {\includegraphics[width=0.2\textwidth]{example-image-b}};
\draw[->] (A) to (B);
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807