# LaTeX TikZ - auto resize block to fit text

I got this kind of code in LaTeX using TikZ:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}

\tikzstyle{block} = [draw,rectangle,fill=blue!50,text width=8em, text centered,minimum height=8mm,node distance=10em]
\tikzstyle{line} = [draw, -latex']

\begin{tikzpicture}
\tikzstyle{every node}=[font=\small]
\node [block, xshift=-3em](start){ST\_Category};
\node [block, right of=start, xshift=5em](process1){Process 1};
\end{tikzpicture}

\end{document}


Blocks got fixed size. All i want to achieve to have those block auto resize to fit longer text. So the block getting withders when text is longer. For example if in first block text will be "DASDASDADASDASDASDAS" it will go over the block borders which will look bad. I what those blocks to automatically expand when the text is longer.

-

## migrated from stackoverflow.comJul 30 '12 at 17:18

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Jul 30 '12 at 17:20

You are specifying that the with of the text is fixed via the option text width=8em. If you just eliminate that option, the box will re-size to the text.

Here is a comparison with text width=8em specified for the first line, but not for the second line:

## Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}

\tikzstyle{block} = [draw, rectangle, fill=blue!50,, text centered, minimum height=8mm,node distance=10em]
\tikzstyle{line} = [draw, -latex']

\tikzstyle{every node}=[font=\small]

\begin{tikzpicture}[text width=8em]