# [Tex/LaTex] Tikz: Creating a rectangle with a fake \parbox

boxestikz-pgf

In the example below, I am trying to get identical blue and red boxes, without any text in the red one. I would like to have the red box exactly identical to the blue one, whose size depends on the content of the parbox, but without inserting any text in it? Is this possible?

\documentclass{book}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[anchor=north] (current page.north) node [fill=red,inner sep=1cm]{\parbox[c][][t]{\paperwidth}{\vphantom{Title}}};
\draw[anchor=north] (current page.north) node [fill=blue,opacity=.5,inner sep=1cm]{\parbox[c][][t]{\paperwidth}{Title}};
\end{tikzpicture}
\end{document}


The issue not explained here in details is that I am using a blend mode of Tikz which affects the text:

\draw[anchor=north] (midpoint) node [fill=black!75!ocre,blend mode=color,text width=\paperwidth,inner sep=1cm]{\parbox[c][][t]{\paperwidth}{\color{white} Text}};


and I want to keep the text as white. One solution is to add the text later in a different node.

No need for extra libraries nor big modification to your code; you're code will work as soon as TeX sees something in the \parbox such as a box of zero width (since the requirement in the question was to have "no text" in the box):

\documentclass{book}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[anchor=north] (current page.north) node [fill=red,inner sep=1cm]{\parbox[c][][t]{\paperwidth}{\mbox{}\vphantom{Title}}};
\draw[anchor=north] (current page.north) node [fill=blue,opacity=.5,inner sep=1cm]{\parbox[c][][t]{\paperwidth}{Title}};
\end{tikzpicture}
\end{document}


As percusse mentioned in his comment you could even dispense with the use of the \parboxes and give the desired width using text width:

\documentclass{book}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[anchor=north] (current page.north) node [fill=red,inner sep=1cm,text width=\paperwidth]{\vphantom{Title}};
\draw[anchor=north] (current page.north) node [fill=blue,opacity=.5,inner sep=1cm,text width=\paperwidth]{Title};
\end{tikzpicture}

\end{document}


The problem with your original code is that the \vphantom gives you the necessary height but the \parbox will still be empty. Adding the \mbox{} allows to set the specified width.