如何去除灰色矩形周围的白色边界框?
这是 tikz 代码
\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
它是 引起的产物framed
。
来自pgfmanual
(第 25 节):
背景矩形的尺寸确定如下:我们从图片的边界框开始。然后在边上添加一定的分隔距离。
您可以使用选项inner frame sep=0pt
关闭此行为,或者开关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}
我稍微修改了您的矩形,例如:如果背景很紧,它实际上位于图片后面,因此框架在矩形后面不可见。黄色矩形实际上是下面的框架。