I am trying to create a flowchart using TikZ and i have few difficulties...

  1. My flowchart doesn't fit into one A4 page
  2. The text Yes \ No is on the line and not on the side of it.
  3. The size of decision (diamond) is to big and the text is not spread over the all surface of the diamond.

Is there a way to split the flowchart into to pages? My wish is to fit it into one page...


I was able to place Yes \ No on top of the line or an the side of it using above, right, links instead of decision answer.

Should i keep using matrix structure? i saw i could also give below of.... What is better in my case?

Here is my flowchart:

\documentclass[ pdftex,




%  9. Paket um Textteile drehen zu kï¿œnnen.

\usetikzlibrary{shapes,arrows,matrix,decorations.pathreplacing,     shapes.geometric}

% Allowing formulas to be spreded over few pages

\tikzset{decision/.style={diamond, draw, fill=blue!20, text badly centered,  node distance=2.5cm, inner sep=0pt,align=center}}
\tikzset{block/.style={drectangle, draw, fill=blue!20, text centered, rounded corners, align=center}}
\tikzset{line/.style={draw, very thick, color=black!50, -latex'}}
\tikzset{start/.style={shape=circle,draw,minimum size=1.2cm,draw=blue!80,fill=blue!20,text centered, align=center}}
\tikzset{decision answer/.style={near start,color=black}}
\tikzset{datashape/.style={ trapezium, draw, trapezium left angle=60, trapezium right angle=-60}}

\begin{tikzpicture}[scale=2, auto, every node/.style={ midway, auto,     font=\footnotesize, anchor=center, >=stealth}]

 \matrix [column sep=5mm,row sep=7mm]
% row 1
&&\node [start] (start){start};&&\\
% row 2
%&&\node [datashape,block,text width=3cm] (buff){Add new measurement, $y_k$ to %buffer};&&\\
&&\node [block,text width=3cm] (measurement){Add new measurement, \\ $y_k$ to
% row 3
\node [decision] (reg status){Is \\ regression status \\ equel True};&%
\node [block]    (update goodness){update \\ Goodness of Fit \\ $\chi_\mathrm{red}^2$};&%
\node [decision] (line pass){Is \\ $\left|\delta \right| < \left( 3.5\cdot %
    \sigma_{\varepsilon} +
            \sigma_{\hat{\beta}_k}\right)$\\ and \\ $\chi_\mathrm{red}^2 <
\node [block]    (update beta_k){Update estimated values \\ $\chi_\mathrm{red}^2$, %
            $\hat{\beta}_k^i$ and $\operatorname{Cov}$};&\\
% row 4
\node [block,text width=3cm] (Reg False){Set regression status = %
% row 5
\node [block,text width=3cm] (create replica){Create a replica of
        current regression solution \\ $i \to i+1$};&
\node [block,text width=3cm] (Update replica){Clean buffer, \\ Update: \\
$\hat{\beta}_k^{i+1}$, $\operatorname{Cov}_k^{i+1}$ and $\chi_\mathrm{red}^2$}; \\
% row 6
\node [decision] (i > 0 1){Is \\ number of regression > 0 \\ $(i > 0)$};&
\node [block]    (update estimate){update estimated values \\ $^{i+1}\chi_\mathrm{red}^2$, %
            $\hat{\beta}_k^{i+1}$ and $\operatorname{Cov}_k^{i+1}$};&
% row 7
\node [decision] (sol val){Is \\ new Solution valid \\ $R^2 < 0.01$};&
\node [block]    (new estimation){Compute new estimation \\ $\hat{\beta}_k$, $R^2$ and %
\node [decision] (if 2){Is \\ regression solution falsh \\ and \\ sufficent
          number of measurements};&\\
% row 8
\node [block]    (set reg true){Set regression status \\ to true};&
% row 9
\node [decision] (i>0 2){Is \\ \# of regression solutions > 0 \\ $(i> 0)$};&
\node [decision] (uniqueness){Does \\ the two samples, \\ $\hat{\beta}_k^i$,
$\hat{\beta}_k^n$ \\ independent};&
\node [block]    (new to i+1){Copy new solution \\ estimation in $i+1$ \\ solution
% row 10
\node [block]    (i to i+1){Delete solution $i$ \\ and instead place \\ solution
          $i+1$ as $i$};&\\
% row 11
&&\node [start] (end){End};&&\\

\begin{scope}[every path/.style=line]
  \path [line] (start)-- (measurement);
  \path [line] (measurement) -| (reg status);
  \path [line] (reg status) -- node[decision answer] {Yes} (update goodness);
  \path [line] (update goodness) -- (line pass);
  \path [line] (line pass) -- node[decision answer] {Yes} (update beta_k);
  \path [line] (line pass) -- node[decision answer] {No}  (Reg False);
  \path [line] (Reg False) -- (create replica);

  • You should add the auto option to the line \tikzset{decision answer/.style={near start,color=black,auto}} instead of manually setting the labels. – Jake May 18 '11 at 12:18

For starters, your flowchart has a lot of whitespace. If you wish to reduce the overall space, you should consider placing the blocks differently. Personally, I use a matrix of math nodes when creating flow charts but others use chains or the positioning of nodes with stuff like left of or below of. They all have pros and cons. Use what you are most comfortable with. Next for the other two questions :

question 2 : replace the part where you add the text to a line by a simple node. I used the following code to achieve what you wanted. Since the same settings are used for every line, only one path command is required; no need for scope either.

\path[line] (start)-- (measurement)
              (measurement) -| (reg status)
              (reg status) --  (update goodness) node[above,midway] {Yes}
              (update goodness) -- (line pass)
              (line pass) --  (update beta_k) node[above,midway]{Yes}
              (line pass) --  (Reg False) node[midway,right] {No}
              (Reg False) -- (create replica);

question 3 : to change the shape of a diamond, use the aspect option. It corresponds to the ratio of the lengths of the diagonals. For example,

decision/.style={diamond,aspect=2, draw, fill=blue!20, text badly centered,  node distance=2.5cm, inner sep=0pt,align=center

should give you what you want.

To draw the chart by positioning the nodes, you must use the positioning library. You may place the initial node wherever you wish, then place the others relative to it. I just let tikz place it. In the following code I removed a lot of stuff from your code, just to see the structure better.






\tikzset{decision/.style={diamond, draw, fill=blue!20, text badly centered,  node distance=2.5cm, inner sep=0pt,align=center}}
\tikzset{block/.style={rectangle, draw, fill=blue!20, text centered, rounded corners, align=center}}
\tikzset{line/.style={draw, very thick, color=black!50, -latex'}}
\tikzset{start/.style={shape=circle,draw,minimum size=1.2cm,draw=blue!80,fill=blue!20,text centered, align=center}}
\tikzset{decision answer/.style={near start,color=black}}

\begin{tikzpicture}[scale=2, auto, every node/.style={font=\footnotesize, >=stealth,node distance=1cm}]

\node [start] (start){start}; 

\node [block,text width=3cm,below= of start] (buff) {Buffer 1}; 

\node [block,text width=3cm,below=of buff] (measurement){Buffer 2}; 

\node [decision,below left=1cm and 2cm of measurement,anchor=north] (status){Regression status};

\node [block,right=of status] (goodness){Goodness of Fit};

\node [decision, right=of goodness] (test){Test};

\node [block,right=of test]    (update){Update};
\node [block,text width=3cm,below=of test] (false){Set};

\path [line] 
    (start)-- (buff) --(measurement)-| (status) --  (goodness) node[above, midway] {Yes} -- (test)
    (test) --  (update) node[above,midway] {Yes}
    (test) --  (false) node[right,midway] {No}



The output is


To finally answer your question about placing nodes in specific places, here is some code that does just that. I added an extra node below the starting node and placed this relative to this node. There are maybe other ways to do this. I would have personally used a matrix, as you had initially done.

\begin{tikzpicture}[scale=2, auto, every node/.style={font=\footnotesize, >=stealth,node distance=1cm,anchor=base,text width=5em}]

\node [start] (start){start}; 

\node [block,text width=3cm,below= of start] (buff) {Buffer 1}; 
\node [block,text width=3cm,below=of buff] (measurement){Buffer 2}; 

\node[below=2cm of measurement] (level three) {};

\node [block,left=1cm of level three] (goodness){Goodness of Fit};
\node [decision,left=of goodness,anchor=center] (status){Regression status};

\node [decision, right=of level three] (test){Test};

\node [block,right=of test]    (update){Update};
\node [block,text width=3cm,below=of test] (false){Set};

\path [line] 
    (start)-- (buff) --(measurement)-| (status) 
    (status.east) --  (goodness) node[above, very near end] {Yes} -- (test)
    (test) --  (update) node[above,very near end] {Yes}
    (test) --  (false) node[right,midway] {No}

  • thank you for your answer. i decided to moved to positioning of nodes and i have difficulty placing: \node [start] (start){start}; in the middle of the page. Is there a way of doing it using positioning of nodes? – Eagle May 18 '11 at 15:02
  • I included an example with node positioning – Frédéric May 18 '11 at 18:23
  • thank you very much for your example, i also applied positioning of nodes system. Unfortunately, your example doesn't answer my question. Let say i would like to place start from the width (latitude) between Goodness of Fit and Test. – Eagle May 18 '11 at 19:40
  • Your positioning question is answered – Frédéric May 18 '11 at 21:12

About the "fit on an A4 page" part:

One simple way would be rescaling the whole picture to the text area size. This can be done by the \resizebox{<width>}{<height>}{<content>} macro from the graphicx package (already loaded by tikz). For larger content I would recommend to use the adjustbox environment of the adjustbox package instead. It does not read its content as argument but as box which is more efficient and causes no issues with complex content like verbatim code. It supports the same options like \includegraphics.

% ...

after many, many years ... as exercise how to draw flowchart on more consistent way :-)

  • define one, named tikzset for flowcharts
  • set default values for node shapes parameters, which can be eventual in drawing of diagram manually simple overwritten
  • node distance is determined only ones
  • use of the library quotes for labeling of edges
  • reduce text height in nodes with reducing linespread

mwe below similarly as in Frédéric answer consider only clear part of OP mwe. i estimate, that complete flowchart can be fit in (portrait oriented) A4 page:

enter image description here

\usetikzlibrary{arrows.meta, positioning, quotes, shapes.geometric}

\tikzset{flowchart/.style ={
    base/.style = {draw=blue!80, fill=blue!20, outer sep=0pt,
                   align=flush center},
decision/.style = {base, diamond, aspect=1.6, inner ysep=0pt,
                   inner xsep=##1},
decision/.default = 2pt,
   block/.style = {base, rounded corners,
                   text width=##1},
 block/.default = 32mm,
   start/.style = {base, circle, minimum size=10mm},
      LA/.style = {% line with arrowhead
                   draw, very thick, color=black!50, -Latex},
      DA/.style = {% decision answer
                   near start,font=\footnotesize, text=black},
  node distance = 6mm and 12mm


\node (start)   [start]                         {Start};
\node (buff)    [block, below=of start]         {Add new
                                                 $y_k$ to buffer};
\node (status)  [decision,below left=of buff]   {Regression\\ status};
\node (good)    [block, at={(buff |- status)}]  {update \\
                                                 Goodness of Fit $\chi_\mathrm{red}^2$};
\node (test)    [decision=-3ex,
                 right=of good]                 {Test\\
            $\abs{\delta}<(3.5\sigma_{\varepsilon} + \sigma_{\hat{\beta}_k})$,\\
            $\chi_\mathrm{red}^2 < 1.6$};
\node (update)  [block, right=of test]          {update estimated %values
            $^{i+1}\chi_\mathrm{red}^2$, $\hat{\beta}_k^{i+1}$, $\Cov_k^{i+1}$};
\node (set)     [block, below=of test]          {Set\\ regression status};
\node (false)   [block, below=of set]           {Create a replica of
                                                 current regression solution:
                                                 $i \to i+1$};
\path [LA]
    (start)     edge (buff)
    (buff)       -|  (status)
    (status)    edge [DA,"Yes"] (good)
    (good)      edge (test)
    (test)      edge [DA,"Yes"] (update)
    (test)      edge [DA,"No"]  (set)
    (set)       edge (false)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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