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 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}
share|improve this question
    
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

2 Answers 2

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}
share|improve this answer
    
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.

\usepackage{adjustbox}
% ...
%
\begin{adjustbox}{width=\textwidth,height=\textheight,keepaspectratio}
\begin{tikzpicture}[...]
  ...
\end{tikzpicture}
\end{adjustbox}
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.