\documentclass[landscape]{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[scale=.5,
show background rectangle,
background rectangle/.style={fill=black},
color=white,help lines/.style={color=lightgray,line width=0.2pt}]
\draw (0,14) node[anchor=north west] {{\bf text}};
\draw (0,13.5) node[anchor=north west] {text};
\draw (0,13) node[anchor=north west] {text};
\draw (0,12.5) node[anchor=north west] {text};
\draw (0,12) node[anchor=north west] {text};
\draw (0,1) node[anchor=north west] {{\bf Deliberately left blank}};
% bounding box
\draw[style=help lines] (11,0.5) rectangle (12.5,14);
\draw[style=help lines] (11.75,0.5) rectangle (13.25,14);
\draw[style=help lines] (14,0.5) rectangle (15.5,14);
\draw[style=help lines] (14.75,0.5) rectangle (16.25,14);
\draw[style=help lines] (17,0.5) rectangle (18.5,14);
\draw[style=help lines] (17.75,0.5) rectangle (19.25,14);
\draw[style=help lines] (20,0.5) rectangle (21.5,14);
\draw[style=help lines] (20.75,0.5) rectangle (22.25,14);
\draw[style=help lines] (23,0.5) rectangle (24.5,14);
\draw[style=help lines] (23.75,0.5) rectangle (25.25,14);
\draw[style=help lines] (0,14) -- (26,14);
\draw[style=help lines] (0,11) -- (26,11);
\draw[style=help lines] (0,7.5) -- (26,7.5);
\draw[style=help lines] (0,3.5) -- (26,3.5);
\draw[style=help lines] (0,1) -- (26,1);
\draw (11,0.5) rectangle (26,14);
\draw (14,0.5) rectangle (23,14);
\draw (17,0.5) rectangle (20,14);
\draw (12.5,14) node[anchor=south] {Year 1};
\draw (15.5,14) node[anchor=south] {Year 2};
\draw (18.5,14) node[anchor=south] {Year 3};
\draw (21.5,14) node[anchor=south] {Year 4};
\draw (24.5,14) node[anchor=south] {Year 5};
% blocks
\filldraw[fill=Silver] (11,13) rectangle (13.25,13.5);
\filldraw[fill=Silver] (11.75,12.5) rectangle (16.25,13);
\filldraw[fill=Silver] (14,12) rectangle (17.75,12.5);
\filldraw[fill=Silver] (15.5,11.5) rectangle (20,12);
%\filldraw[fill=Silver] (17,11) rectangle (17.75,11.5);
\filldraw[fill=Silver] (13.25,10) rectangle (16.25,10.5);
\filldraw[fill=Silver] (14.75,9.5) rectangle (18.5,10);
\filldraw[fill=Silver] (17,9) rectangle (20.75,9.5);
\filldraw[fill=Silver] (18.5,8.5) rectangle (22.25,9);
%\filldraw[fill=Silver] (20.75,8) rectangle (20,8.5);
\filldraw[fill=Silver] (14,6.5) rectangle (20,7);
\filldraw[fill=Silver] (19.25,6) rectangle (24.5,6.5);
\filldraw[fill=Silver] (15.5,5.5) rectangle (17.75,6);
\filldraw[fill=Silver] (17.75,5) rectangle (20, 5.5);
\filldraw[fill=Silver] (20,4.5) rectangle (22.25,5);
\filldraw[fill=Silver] (22.25,4) rectangle (24.5,4.5);
\filldraw[fill=Silver] (11,2.5) rectangle (13.25,3);
\filldraw[fill=Silver] (13.25,2) rectangle (15.5,2.5);
\filldraw[fill=Silver] (15.5,1.5) rectangle (24.5, 2);
\filldraw[fill=Silver] (17.75,1) rectangle (24.5,1.5);
\filldraw[fill=Silver] (24.5,0.5) rectangle (26,1);
\end{tikzpicture}
\end{document}
![enter image description here](https://i.stack.imgur.com/myCEq.png)
I just had a similar question marked as a duplicate of this one. Here is the link. Unfortunately, the answer posted here was not marked as an answer and OP indicated it as not working. Credit for this approach goes to @symbol-1.
As noted by @percusse here and @cfr and @symbol-1 in the link, the result will be viewer dependent. Examples of viewer differences provided below the code.
Here is modified from the OP and @percusse's answer using transparency group=knockout
in the scope
environment options:
\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\path[pattern=crosshatch dots light steel blue](-2,-2) rectangle (2,2);
\begin{scope}[transparency group=knockout]
\draw (-2,0) to node(aaaaa){} (2,0);
\path (aaaaa) node[fill,opacity=0,text opacity=1]{aaaaa};
\end{scope}
\end{tikzpicture}
\end{document}
You can change the background to anything you like and no other changes are necessary. If you change the text to be longer/short, the background opacity will resize accordingly - i.e. no changes other than the label name.
In some PDF viewers (e.g. SumatraPDF, TeXworks previewer, etc.):
![Result of non-conforming PDF viewers](https://i.stack.imgur.com/GneQX.png)
In other PDF viewers (e.g. Adobe Acrobat):
![Result of conforming PDF viewers](https://i.stack.imgur.com/NEkgc.png)
The PDF is the same in both cases. I simply took a screenshot of it opened in two different PDF viewers. It seems the background is affected as well, but the focus here is the transparency.
Also, here is an example of an additional node with text going vertically to illustrate what happens with transparency group=knockout
with multiple nodes:
\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\path[pattern=crosshatch dots light steel blue](-2,-2) rectangle (2,2);
\begin{scope}[transparency group=knockout]
\draw (-2,0) to node(aaaaa){} (2,0);
\path (aaaaa) node[fill,opacity=0,text opacity=1]{aaaaa};
\draw (0,-2) to node(bbbbb){} (0,2);
\path (bbbbb) node[fill,opacity=0,text opacity=1]{\rotatebox[origin=c]{90}{bbbbb}};
\draw (-2,-0.35) to node(ccccc){} (2,-0.35);
\path (ccccc) node[fill=red,text opacity=1]{ccccc};
\end{scope}
\end{tikzpicture}
In some PDF viewers (e.g. SumatraPDF, TeXworks previewer, etc.):
![Result of second example in non-conforming PDF viewers](https://i.stack.imgur.com/Oddk5.png)
In other PDF viewers (e.g. Adobe Acrobat):
![Result of second example in conforming PDF viewers](https://i.stack.imgur.com/BFP6G.png)
You will notice that whichever item is last with opacity=0
takes precedence over the previous item(s). If you flip the aaaaa
and bbbbb
lines and nodes (i.e bbbbb
occurs first), for example, you'll see this (in the conforming PDF viewers):
![Result of third example in conforming PDF viewers](https://i.stack.imgur.com/y60sR.png)
opacity=0
also takes precedence over other items which do not have opacity. For example, if we move the ccccc
node/lines first within the tikzpicture
, here is the result:
![Result of fourth example in conforming PDF viewers](https://i.stack.imgur.com/Nbw10.png)
Just remember! If your picture is very complicated and you open it in an old or (transparency) non-conforming PDF viewer, it will not be what you expect.
If you have many nodes with transparency and you do not like the overlapping issue, you will need to adjust the order of the nodes, xshift
and yshift
, and/or place the nodes in different positions completely.
Best Answer
You can use the
fill
key to “delete” the background. As the comments show you must care to set no other color after the fill key withcolor
or just using the color name as an option. That will overwrite the color given tofill
. As you can see in the examplecolor
set the color for filling, drawing and the text.To change the text or drawing color you can use the
draw
andtext
options, which won’t affect thefill
color.