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 got the following flow chart diagram in tikz. enter image description here


MWE

\documentclass{standalone}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc, shapes, arrows, positioning}

\begin{document}


% Define block styles

\tikzstyle{block} = 
    [
        rectangle
      , draw
     % , fill=blue!20
      , text width=12.5em
      , text centered
      , node distance=1.5cm
      , rounded corners
      , minimum height=2em
      ]

\tikzstyle{block2} = 
    [
        rectangle
      , draw
     % , fill=blue!20
      , text width=6.5em
      , text centered
      , node distance=1.5cm
      , rounded corners
      , minimum height=2em
      ]

\tikzstyle{line} = 
    [
        draw
     , -latex'
     ]



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


  % Place nodes
    \node [block] (ZeroSlopes) {Test Slopes are equal to Zero, i.e.,\\ $\textrm{H}_{0}:\beta_{1}=\beta_{1}=\ldots=\beta_{t}=0$};
    \node [block, below left = 2.0cm and 0.1cm  of ZeroSlopes] (CommonSlopes) {Test Slopes are equal, i.e.,\\ $\textrm{H}_{0}:\beta_{1}=\beta_{1}=\ldots=\beta_{t}=\beta$};
    \node [block, below right = 2.0cm and 0.1cm   of ZeroSlopes] (ZeroSlope) {Fit Common  Slope \& Test Slope is equal to Zero, i.e.,\\ $\textrm{H}_{0}:\beta=0$};



    \node [block2, below left of=CommonSlopes, node distance=4.5cm] (UnequalSlopes) {Fit Unequal Slopes Model};
    \node [block2, below right of=CommonSlopes, node distance=4.5cm] (CommonSlope) {Fit a Common Slope Model};
    \node [block2, below left of=ZeroSlope, node distance=4.5cm] (ParallelLines) {Fit Parallel Lines Model};
    \node [block2, below right of=ZeroSlope, node distance=4.5cm] (ANOVA) {Fit ANOVA Model};


  % Draw edges
    \path[line] let \p1=(ZeroSlopes.south), \p2=(CommonSlopes.north) in (ZeroSlopes.south) --  +(0,0.5*\y2-0.5*\y1) -| node [pos=0.3, above] {Reject} (CommonSlopes.north);
    \path[line] let \p1=(ZeroSlopes.south), \p2=(ZeroSlope.north) in (ZeroSlopes.south) -- +(0,0.5*\y2-0.5*\y1) -| node [pos=0.3, above] {Retain} (ZeroSlope.north);

    \path[line] let \p1=(CommonSlopes.south), \p2=(UnequalSlopes.north) in (CommonSlopes.south) -- +(0,0.5*\y2-0.5*\y1) -| node [pos=0.3, above] {Reject} (UnequalSlopes.north);
    \path[line] let \p1=(CommonSlopes.south), \p2=(CommonSlope.north) in (CommonSlopes.south) -- +(0,0.5*\y2-0.5*\y1) -| node [pos=0.3, above] {Retain} (CommonSlope.north);

    \path[line] let \p1=(ZeroSlope.south), \p2=(ParallelLines.north) in (ZeroSlope.south) -- +(0,0.5*\y2-0.5*\y1) -| node [pos=0.3, above] {Reject} (ParallelLines.north);
    \path[line] let \p1=(ZeroSlope.south), \p2=(ANOVA.north) in (ZeroSlope.south) -- +(0,0.5*\y2-0.5*\y1) -| node [pos=0.3, above] {Retain} (ANOVA.north);


\end{tikzpicture}

\end{document}

Question


I've problem with adjusting the horizontal and vertical distances between the nodes. You can see that the nodes horizontally are far apart from each other. Is there any better better approach to make flow charts with tikz? Any help to resolve the problem will be highly appreciated. Thanks in advance.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

This solution proposes a matrix node scheme to draw the flow diagram. The horizontal and vertical distances between the nodes can be adjusted via column sep and row sep, respectively.

enter image description here

By adjusting column sep from -5m to -20mm, one gets

enter image description here

Code:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning}

\begin{document}

\tikzstyle{block} = 
    [
        rectangle
      , draw
     %, fill=blue!20
      , text width=12.5em
      , text centered
     %, node distance=1.5cm
      , rounded corners
      , minimum height=2em
      ]

\tikzstyle{block2} = 
    [
        rectangle
      , draw
     %, fill=blue!20
      , text width=6.5em
      , text centered
     %, node distance=1.5cm
      , rounded corners
      , minimum height=2em
      ]

\tikzstyle{line} = 
    [
        draw
     , -latex'
     ]
\begin{tikzpicture}       % a 3 x 7 matrix
  \matrix (mat) [matrix of nodes, nodes=block, column sep=-5mm, row sep=1.5cm] 
{
& & &\node [block] (ZeroSlopes) {Test Slopes are equal to Zero, i.e.,\\ $\textrm{H}_{0}:\beta_{1}=\beta_{1}=\ldots= \beta_{t}=0$};  & & & \\ 
&\node [block] (CommonSlopes) {Test Slopes are equal, i.e.,\\ $\textrm{H}_{0}:\beta_{1}=\beta_{1}=\ldots
=\beta_{t}=\beta$};  & & & &
    \node [block] (ZeroSlope)  {Fit Common  Slope \& Test Slope is equal to Zero, i.e.,\\ $\textrm{H}_{0}:\beta=0$}; &     \\
\node [block2] (UnequalSlopes) {Fit Unequal Slopes Model};
&&
\node [block2] (CommonSlope)   {Fit a Common Slope Model};        
&&
\node [block2] (ParallelLines) {Fit Parallel Lines Model};
&&
\node [block2] (ANOVA) {Fit ANOVA Model};\\ 
};  
% Draw edges
\path[line] (ZeroSlopes.south)    --+(0,-0.5) -| node [pos=0.3, above] {Reject} (CommonSlopes.north);
\path[line] (ZeroSlopes.south)   -- +(0,-0.5) -| node [pos=0.3, above] {Retain} (ZeroSlope.north);
%
\path[line] (CommonSlopes.south) -- +(0,-0.8) -| node [pos=0.3, above] {Reject} (UnequalSlopes.north);
\path[line] (CommonSlopes.south) -- +(0,-0.8) -| node [pos=0.3, above] {Retain} (CommonSlope.north);
%
\path[line] (ZeroSlope.south)    -- +(0,-0.8) -| node [pos=0.3, above] {Reject} (ParallelLines.north);
\path[line] (ZeroSlope.south)    -- +(0,-0.8) -| node [pos=0.3, above] {Retain} (ANOVA.north);
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks @Jesse for your answer. I'll keep the question open and will see if have another solution. Thanks for your efforts and help. –  MYaseen208 Jan 19 at 11:16
    
@MYaseen208 -- Please do. –  Jesse Jan 19 at 11:29
add comment

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.