I've been trying to get the fit
key in TikZ to scale a node so that it matches only the height of it's fit nodes but I haven't been successful. I'm trying to get the red box to be the size of the blue boxes:
\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{positioning,fit}
\newcommand{\filler}[1]{\begin{minipage}{12cm}\small\lipsum[#1]\end{minipage}}
\thispagestyle{empty}
\begin{document}
\begin{tikzpicture}[node distance=0pt,outer sep = 2pt, text centered]
\tikzstyle{box}=[rectangle,draw,inner sep=0em]
\tikzstyle{vline}=[box, rotate=90, fill=red!20, minimum height=1cm]
\tikzstyle{hline}=[box, fill=blue!20, minimum width=10cm]
\node[vline] (a) at (0,0) {\textbf{How do I extend this node to fit?}};
\node[hline] (b1) [below right = of a.south east] {\filler{1}};
\node[hline] (b2) [below = of b1] {\filler{2}};
\node[hline] (b3) [below = of b2] {\filler{3}};
\end{tikzpicture}
\end{document}
Question: for node a
, how do I keep the x dimension fixed, while the y dimension scales to the height of nodes (b1,b2,b3)
?
Best Answer
Summary
minipage
environment from your\filler
macro and replacedtext centered
withtext justified
in yourtikzpicture
options as this does the same effect.node distance=0pt
withnode distance=2pt
.coordinates
:top
andbottom
were defined so for use with thefit
option for the nodea
. Now, instead of positioningb1
in terms of nodea
, nodea
was positioned in terms of nodesb1
andb3
usingfit
library. Update: It is enough to use twocoordinates
for thefit
as the node(a)
will simply create a bounding box around the two coordinates and any coordinate defined between these two points. As long as the coordinates are aligned, there is no harm in doing this as coordinates are theoretically dimensionless. And, for the10pt
width of the node(a)
, I thought that was what you were after; if not, you can change it to a dimension that you like:)
a
is done with thelabel
option. Update: The work-around is needed, since with this solution, doingrotate=90
directly in the node option will rotate both the node shape and the text.Update
\tikzstyle
with\tikzset
as in Gonzalo's answer.