My question is almost opposite to: this question.
I have defined a block:
\begin{tikzpicture}[node distance = 2cm, auto,->=stealth,point/.style=
{circle,fill=red,minimum size=0pt,inner sep=0pt}]
\tikzstyle{block} = [rectangle, draw,thick,fill=blue!0,
text centered, rounded corners, minimum height=1em]
\node [block] (start) {Start};
\node [block,below of=start] (start) {Start and blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah};
\end{tikzpicture}
The block adjusts itself to accommodate text.
But I would like to control the width of the block by using text width=15em
:
\tikzstyle{block} = [rectangle, draw,thick,fill=blue!0,text width=20em,<---------=
text centered, rounded corners, minimum height=1em]
I get this:
Though the second block looks good, the first block (start
) has lot of empty space in it. My question is
How to adjust the width of the block according to the text and at the same time limiting the maximum width of the block to (say) 15em?
In other words, How to make the first block to fit with start
? Or generally speaking,
How to adjust the block size automatically to fit the text with maximum width of block as 15em?
Pl. note: I am aware that I can define block2
with a suitable width and put start
in it. But my constraint is to use the single tikzstyle.
Best Answer
I guess there is no TikZ way, but you can use the
varwidth
package:You may wrap the
{varwidth}
environment in a shorter macro …Update
It is possible to use
execute at begin/end node
to include{varwidth}
in the sytle definition: