Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create flowchart, using tikz:

\begin{document}

\tikzstyle{decision} = [diamond, draw, fill=blue!20, minimum size=2em, text badly centered,     node distance=2.5cm, inner sep=0pt]

\tikzstyle{block}    = [rectangle, draw, fill=blue!20, minimum size=2em, text centered, rounded corners, minimum height=4em]

\tikzstyle{line}     = [draw, very thick, color=black!50, -latex']

\tikzstyle{cloud}    = [draw, ellipse,fill=red!20, node distance=2.5cm, minimum height=2em]

\tikzstyle{circle}   = [draw, circle,fill=red!20, node distance=2.5cm, minimum height=2em]

 \tikzstyle{start}    = [circle,draw,minimum size=1.2cm ,draw=blue!80, fill=blue!20,text centered]

 \tikzstyle{decision answer}=[near start,color=black]

 \begin{tikzpicture}[scale=2, node distance = 2cm, auto]

 \tikzstyle{every node}=[midway,auto,font=\scriptsize, anchor=center]
 \matrix [column sep=5mm,row sep=7mm]
  {
\node [start] (start){start};\\
\node [block] (buff){Add new measurement, $y_k$ to buffer};\\
  };

 \end{tikzpicture}
 \end{document}

I would like to present the text Add new measurement, $y_k$ to buffer in two lines. When I add \\ I get a LaTeX error.

Using text width=4.5em causes the line to split, but not where I want and then the text is not centered any longer.

share|improve this question
    
Please don't add [solved] to the question title. Questions with accepted answers are already displayed differently. –  Martin Scharrer May 12 '11 at 16:22
    
See also the TikZ example on texample.net, e.g.: texample.net/tikz/examples/assignment-structure –  Martin Scharrer May 12 '11 at 16:39

2 Answers 2

up vote 4 down vote accepted

If you want to place one node below another use below of=<node name> or load the positioning library with \usetikzlibrary{positioning} and use below=<optional length> of <node name>.

Using \\ inside the node using text width works for me. One big problem of your code is that you define a circle style which uses circle inside and therefore recursively calls itself. You need to use shape=circle in this case, but I would recommend to use a different name. Also \tikzstyle should not be used any longer. See my comments in the code.

\documentclass{article}
\usepackage{tikz}
\begin{document}

% Use `\tikzset{name/.style={...}}` instead of `\tikzstyle{name} = [...]`
\tikzstyle{decision} = [diamond, draw, fill=blue!20, minimum size=2em, text badly centered,     node distance=2.5cm, inner sep=0pt]
\tikzstyle{block}    = [rectangle, draw, fill=blue!20, minimum size=2em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line}     = [draw, very thick, color=black!50, -latex']
\tikzstyle{cloud}    = [draw, ellipse,fill=red!20, node distance=2.5cm, minimum height=2em]
% Recursive Reference! Use `shape=circle` instead of `circle`.
%\tikzstyle{circle}   = [draw, circle,fill=red!20, node distance=2.5cm, minimum height=2em]
\tikzstyle{start}    = [circle,draw,minimum size=1.2cm ,draw=blue!80, fill=blue!20,text centered]
\tikzstyle{decision answer}=[near start,color=black]

\begin{tikzpicture}[scale=2, node distance = 2cm, auto, every node/.style={midway,auto,font=\scriptsize, anchor=center}]
   \node [start] (start) {start};
   \node [below of=start,block,text width=4.5cm] (buff) {Add new measurement,\\ $y_k$ to buffer};
   \draw [->] (start) edge (buff);
\end{tikzpicture}
\end{document}

Result

share|improve this answer
    
thanks for your suggestions. it worked –  Eagle May 12 '11 at 16:16
    
i tried adding: \node [block] (buff){update Goodness of Fit \\ $\chi_\mathrm{red}^2$}; at the second line, so i have start in the first line and two elements in the second line. I get that that the two elements centers at the second line are not in the same hight... what should i do? –  Eagle May 12 '11 at 16:29
    
@Eagle: I can't follow you fully. You want to have a second block below the "Add new measurement" one or beside it? The position of the code lines does not affect the position of the nodes directly. You need to give the new block a different name and e.g. add [below of=buff] to have it below the existing one. –  Martin Scharrer May 12 '11 at 16:37
    
lets say i have in the 1st line (where Start is) one element and on the 2nd line 2 elements (Add new measurment.. and something else) which i would like to create a Triangle presentation (i hope i am clear, Start at the top and the two other elements at below). How could i do it? –  Eagle May 12 '11 at 17:17
    
@Eagle: You can use below left and below right for positioning. –  Martin Scharrer May 12 '11 at 17:45

Just use align=center instead of text width=4.5em and you can use \\ without setting a fixed width.

See also the PGF Manual, section “16.4.3 Text Parameters: Alignment and Width for Multi-Line Text”

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.