2

How can I remove the white bounding box around the gray rectangles?

enter image description here

Here's the tikz code

\begin{tikzpicture}[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]
\fill[fill=gray!30] (0,0) rectangle (8.1,0.6);
\fill[fill=gray!10] (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}
  • 1
    what's the definition framed? – percusse Mar 11 '14 at 9:55
  • @percusse: it should be an alias for show background rectangle. – Claudio Fiandrino Mar 11 '14 at 10:00
  • Yes, it is used to show the rectangle, so I can see the white space around the picture – Filippo Bistaffa Mar 11 '14 at 10:39
2

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.

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.