12

I have a simple gantt chart made using tikzpicture. How can I invert the whole thing so it is white on black? If I change the node lines to node[anchor=north west, text=white, fill=black] then this inverts just that cell. I would like the entire picture to be inverted. I wondered if something from Fitting background in Tikz could be used but I am not sure how to get it to work.

Example of picture whose colours I would like to invert.

\documentclass[10pt,landscape]{standalone}

\setlength{\parskip}{3pt}

\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{xspace}

\renewcommand{\rmdefault}{phv} % Arial
\renewcommand{\sfdefault}{phv} % Arial

\pagestyle{empty}

\begin{document}

\noindent \begin{tikzpicture}

\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}

2 Answers 2

13
\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

0
7

The color and background can be given as options to the whole picture. The style help lines explicitly sets the color to gray, therefore it is redefined.

\usepackage{tikz}
\usetikzlibrary{backgrounds}

\begin{tikzpicture}[
  show background rectangle, 
  background rectangle/.style={fill=black},
  color=white,
  help lines/.style={color=lightgray,line width=.2pt},
]

Edit: \usetikzlibrary{backgrounds} added and style redefinition simplified.

6
  • @HeikeOberdiek. This doesn't work for me. If I change the example I gave to [...]\begin{document} \noindent \begin{tikzpicture}[ show background rectangle, background rectangle/.style={fill=black}, color=white, ] \tikzstyle{help lines}=[color=lightgray,line width=0.2pt] [...] I get an image with no visible text, and a white background.
    – Simd
    Commented Aug 15, 2012 at 18:54
  • @Raphael Try \begin{tikzpicture}[ show background rectangle, background rectangle/.style={fill=black}, color=white,help lines/.style={color=lightgray,line width=0.2pt}]. Possible text=white Commented Aug 15, 2012 at 18:59
  • Same problem with [...]\begin{document} \noindent \begin{tikzpicture}[ 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}};[...]
    – Simd
    Commented Aug 15, 2012 at 19:01
  • @Raphael Works fine for me ! Commented Aug 15, 2012 at 19:02
  • Oh I see. I reran pdflatex from the command line and now I get ! Package pgfkeys Error: I do not know the key '/tikz/show background rectangle ' and I am going to ignore it. Perhaps you misspelled it. As well as "Pretend that you're Hercule Poirot: Examine all clues, and deduce the truth by order and method. " :)
    – Simd
    Commented Aug 15, 2012 at 19:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .