[Tex/LaTex] TikZ: remove margin, padding, border around nodes containing images

arrowsgraphicsmarginsspacingtikz-pgf

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?

Best Answer

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