[Tex/LaTex] Fit flowchart into one page

scalingtikz-pgftikz-trees

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…

EDIT

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,
    a4paper,
    oneside,
    10pt,
    openright,
    titlepage,
    fleqn,
    1headlines,
    headinclude,
    footinclude,
    bibliography=totoc,
    version=first
]{scrbook}

\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\selectlanguage{english}
\usepackage{a4wide}
\parindent0pt

\usepackage[fleqn]{amsmath}
\usepackage[fleqn,intlimits]{empheq}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{dsfont}
\usepackage{mathtools}

%
%  9. Paket um Textteile drehen zu kï¿œnnen.
%
\usepackage[landscape,a4paper]{geometry}
\usepackage{graphicx}

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

% Allowing formulas to be spreded over few pages
\allowdisplaybreaks[4]

\begin{document}
\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
buffer};&&\\
% 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 <
          1.6$};&
\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 = %
      False};
&\\
% 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 %
         $\operatorname{Cov}_k^{i+1}$};&
\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
          estimation};&\\
% 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);
\end{scope}
\end{tikzpicture}

\end{document}

Best Answer

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.

\documentclass[]{scrbook}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\selectlanguage{english}

\usepackage[]{amsmath,amssymb,amsthm}
\usepackage{mathtools}

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

\begin{document} 

\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}
    ;

\end{tikzpicture}

\end{document} 

The output is

chart

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}
    ;

\end{tikzpicture}