You could work around this by using two nodes instead of one: The first contains just the text, the second uses the fit
library to draw a rectangle of a specified minimum height around the text.
I've written a style called add rectangle
that takes an optional height and uses the append after command
style to add a second node directly after the text node.
In order to fill the background, you can use the backgrounds
library and place the rectangle on the background layer using the pgfonlayer
environment.
\documentclass{scrreprt}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc,backgrounds}
\usepackage{varwidth}
\tikzset{
add rectangle/.style={
alias=tempname,
append after command={
; \begin{pgfonlayer}{background}
\node [
fill=yellow,
draw=yellow!80!black,
fit={(tempname) ($(tempname.north)+(0,-#1)$)},
inner sep=0pt] {};
\end{pgfonlayer} \path
}
},
add rectangle/.default=2cm
}
\begin{document}
\begin{tikzpicture}
\node (left) [
add rectangle=2cm
] {%
\begin{varwidth}{3cm}%
Short%
\end{varwidth}%
};
\node at (left.north east) [name=middle,anchor=north west,add rectangle=2cm] {%
\begin{varwidth}{3cm}%
Somehow a longer text for testing%
\end{varwidth}%
};
\node at (middle.north east) [anchor=north west,add rectangle=2cm] {%
\begin{varwidth}{3cm}%
Somehow a longer text for testing. This is a really long text that will stretch the box vertically.%
\end{varwidth}%
};
\end{tikzpicture}
\end{document}
You can stick to your "MS Word's 2 column 1 row table" approach:
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\begin{figure}[t]
\begin{tabular}{|p{\dimexpr.5\linewidth-2\tabcolsep}|p{\dimexpr.5\linewidth-2\tabcolsep}}
\cline{1-1}
\lipsum[1] & \lipsum[2] \\ \cline{1-1}
\end{tabular}
\end{figure}
\begin{figure}[t]
\begin{tabular}{p{\dimexpr.5\linewidth-2\tabcolsep}|p{\dimexpr.5\linewidth-2\tabcolsep}|}
\cline{2-2}
\lipsum[1] & \lipsum[2] \\ \cline{2-2}
\end{tabular}
\end{figure}
\end{document}
The two figure
s in the above MWE contains a boxed left and right block, respectively. Since both cells (regardless of content) is set inside a 1 x 2 table, the sizes will expand according to the same rules as in your requirement.
The tabular
is constructed with only 2 p
aragraph columns of width .5\linewidth-2\tabcolsep
, which makes it fit inside the text block exactly. \cline
draws a horizontal rule across the specified columns.
Best Answer
The environment
varwidth
from the package of the same name needs only a length which will be the maximum of the allowed box width