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}
It is an artifact induced by framed
.
From the pgfmanual
(section 25):
The size of the background rectangle is determined as follows: We start with the bounding box of the
picture. Then, a certain separator distance is added on the sides.
You can use the option inner frame sep=0pt
to turn this behavior off, or the switch tight background
.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[tight background, background rectangle/.style={fill=yellow}, framed]
\tikzstyle{B1}=[anchor=west,solid,rectangle,black,draw,minimum height=0.45cm,minimum width=1cm,fill=orange!30]
\tikzstyle{B2}=[anchor=west,solid,rectangle,black,draw,minimum height=0.45cm,minimum width=1cm,fill=green!30]
\tikzstyle{B3}=[anchor=west,solid,rectangle,black,draw,minimum height=0.45cm,minimum width=1cm,fill=blue!30]
\path[fill=gray!30] (0,0) rectangle (8.1,0.6);
\path (0,0.6) rectangle (8.1,1.2);
\node[B1] at (2,0.9) {};
\node[B2] at (3,0.9) {};
\node[B3] at (4,0.9) {};
\node[B1] at (5,0.9) {};
\node[B2] at (6,0.9) {};
\node[B3] at (7,0.9) {};
\node[B1] at (3,0.3) {};
\node[B2] at (4,0.3) {};
\node[B3] at (5,0.3) {};
\end{tikzpicture}
\end{document}
I modified your rectangles a bit, for the example: if the background is tight, it is actually behind the picture, so the frame is invisible behind the rectangles. The yellow rectangle is actually the frame, below.
Best Answer
The standalone package by default crops the page to its contents. There is also a
border
option (also calledmargin
, which I think is a better name) that allows you to put a white space margin around it. You can even specify all four margins differently. Here is an example:N.B. The gray border is not part of the file. It is the background of the viewer, included to show the size of the resulting output.