I am creating a flow chart and the flowchart goes out of the page border. Could someone help me?

This is my code:

\usetikzlibrary{shapes.geometric, arrows}



\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black,text width=3cm, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered,text width=2cm, draw=black, fill=green!30]

\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{tikzpicture}[node distance=2cm]
    \node (dec1) [decision] {dec1};
    \node (dec2) [decision, below of=dec1 , right of=dec1, yshift=-1.5cm, xshift=2cm] {dec2};
    \node (dec3) [decision, below of=dec1 , left of=dec1,yshift=-1.5cm , xshift=-2cm] {dec3};
    \node (dec4) [decision, below of= dec3 , right of=dec3,yshift=-1.5cm , xshift=1cm] {dec4};
    \node (dec5) [decision, below of= dec2 , left of=dec2,yshift=-1.5cm , xshift=0.3cm] {dec5};
    \node (dec6) [decision, below of= dec4 , left of=dec4,yshift=-1cm , xshift=-2.5cm] {dec6};
    \node (dec7) [decision, below of= dec5 , right of=dec4,yshift=-1cm , xshift=5.5cm] {dec7};

    \node (box1) [startstop,  below of=dec4, yshift=-1cm, xshift=-0.5cm ] {box1};
    \node (box2) [startstop,  below of=dec5, yshift=-1cm,xshift=0.5cm ] {box2};
    \node (box3) [startstop,  below of=dec6, left of=dec6 ,yshift=-1cm] {box3};
    \node (box4) [startstop,  below of=dec6, right of=dec6 ,yshift=-1cm] {box4};
    \node (box5) [startstop,  below of=dec7, left of=dec7 ,yshift=-1cm] {box5};
    \node (box6) [startstop,  below of=dec7, right of=dec7 ,yshift=-1cm] {box6};

3 Answers 3


My modifications:

  • Define tikzstyles minsize and textwidth to modify the minimum width etc. for all other tikzstyles (if you just scale to 0.5 the text will get very small).
  • Use below=of dec1 using the tikzlibrary positioning instead of below of=dec1 (see Difference between “right of=” and “right=of” in PGF/TikZ)
  • If you use below=of dec1, right=of dec1 as option, the first has no effect. Therefore use below right=of dec1. In this way, many manual adjustments (with xshift and yshift) can be saved. (A solution without xshift and yshift is given by Zarko)
  • I use \usepackage{showframe} just to show the margin.
  • Then you can use scale=xx and every node/.style={scale=xx} as Bobyandbob suggested in the comment.
  • As Zarko and Torbjørn T. mentioned: tikzstyle is deprecated. Instead tikzset should be used (see: Should \tikzset or \tikzstyle be used to define TikZ styles?).

Note: For the treelike structure you could also have a look at the forest-package.

\usetikzlibrary{shapes.geometric, arrows, positioning}


    minsize/.style={minimum width=15mm, minimum height=10mm},
    textwidth/.style={text width=15mm},
    startstop/.style={rectangle, rounded corners, minsize, text centered, draw=black,textwidth, fill=red!30},
    io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minsize, text centered, draw=black, fill=blue!30},
    process/.style={rectangle, minsize, text centered, draw=black, fill=orange!30},
    decision/.style={diamond, minsize, text centered, textwidth, draw=black, fill=green!30},


\begin{tikzpicture}[node distance=10mm, scale=0.65, every node/.style={scale=0.78}]
    \node (dec1) [decision] {dec1};
    \node (dec2) [decision, below right=of dec1, xshift=15mm] {dec2};
    \node (dec3) [decision, below left=of dec1, xshift=-15mm] {dec3};
    \node (dec4) [decision, below right=of dec3] {dec4};
    \node (dec5) [decision, below left=of dec2] {dec5};
    \node (dec6) [decision, below left=of dec4, xshift=-15mm] {dec6};
    \node (dec7) [decision, below right=of dec5, xshift=15mm] {dec7};

    \node (box1) [startstop, below=of dec4] {box1};
    \node (box2) [startstop, below=of dec5] {box2};
    \node (box3) [startstop, below left=of dec6, xshift=10mm] {box3};
    \node (box4) [startstop, below right=of dec6, xshift=-10mm] {box4};
    \node (box5) [startstop, below left=of dec7, xshift=10mm] {box5};
    \node (box6) [startstop, below right=of dec7, xshift=-10mm] {box6};

enter image description here

  • use of \tikzstyle is deprecated. use \tikzset instead :)
    – Zarko
    Aug 10, 2017 at 12:17
  • @Zarko I modified the answer.
    – dexteritas
    Aug 10, 2017 at 13:30

You obviously need to move things closer together, the code below is one suggestion for doing that. I've changed a few things from your original code, but I'm not entirely sure if the output is correct. But to summarize the changes:

  • tikz loads xcolor, so the \usepackage{color} is strictly speaking not necessary.
  • The showframe package I added is only for the example, what it does is put a box around the text area. You want to remove it for your document.
  • It may be better to load the positioning library and use right=of instead of right of=, see Difference between "right of=" and "right=of" in PGF/TikZ
  • You can't use both below=of/below of= and right=of/right of= for the same node. Whichever of those is used last will only take precedence over the other. This is why you needed all those extra shifts. But you do have below right=of which can be used instead.
  • \tikzstyle is usually considered deprecated, and \tikzset{style1/.style={...}, style2/.style={...}} should be used instead, see Should \tikzset or \tikzstyle be used to define TikZ styles? for some discussion around this.
  • I've changed the node distance to node distance=1cm and 2cm. The first value is the vertical distance, the second is the horizontal. See section 17.5.3 Advanced placement options in the TikZ manual (for version 3.0.1a) for more details. That section describes the positioning library.
  • There are still some manual shifts here and there, but less than it was.

output of code

\usepackage{showframe} % only to show the text boundaries
  positioning % added

    rounded corners,
    minimum height=1cm,
    text centered,
    text width=2cm, % modified
    font=\small, % added
    inner sep=1pt % added
  io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
  process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
    text centered,
    text width=2cm,
    inner sep=0pt % added

\begin{tikzpicture}[node distance=1cm and 2cm]
\node (dec1) [decision] {dec1};
\node (dec2) [decision, below right=of dec1] {dec2};
\node (dec3) [decision, below left=of dec1] {dec3};
\node (dec4) [decision, below right=of dec3,xshift=-1.5cm] {dec4};
\node (dec5) [decision, below left=of dec2,xshift=1.5cm] {dec5};
\node (dec6) [decision, below=0mm of dec4,xshift=-20mm] {dec6};
\node (dec7) [decision, below=0mm of dec5,xshift=20mm] {dec7};

\node (box1) [startstop, right=2mm of dec6] {box1};
\node (box2) [startstop, left=2mm of dec7] {box2};
\node (box3) [startstop, below=of dec6,anchor=east,xshift=-3mm] {box3};
\node (box4) [startstop, below=of dec6,anchor=west,xshift=3mm] {box4};
\node (box5) [startstop, below=of dec7,anchor=east,xshift=-3mm] {box5};
\node (box6) [startstop, below=of dec7,anchor=west,xshift=3mm] {box6};

  • 1
    Nice. Many same adjustments but a few additional.
    – dexteritas
    Aug 10, 2017 at 9:17

one more variation (with smaller nodes' shapes and fonts, using only library positioning for node placement, nodes' styles, slightly modified are defined as tikzpicture options):

enter image description here

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

   node distance = 14mm and 7mm,
     base/.style = {draw, text width=15mm, minimum height=9mm,
                    font=\small, align=center},
startstop/.style = {base, rounded corners, fill=red!30},
       io/.style = {base,
                    trapezium, trapezium left angle=70, trapezium right angle=110,
                    trapezium stretches, fill=blue!30},
  process/.style = {base, fill=orange!30},
 decision/.style = {base, diamond, aspect=1.2, fill=green!30},
\node (dec1) [decision] {dec1};
\node (dec2) [decision, below right=14mm and 22mm of dec1] {dec2};
\node (dec3) [decision, below left =14mm and 22mm of dec1] {dec3};
\node (dec4) [decision, below right=of dec3] {dec4};
\node (dec5) [decision, below left =of dec2] {dec5};
\node (dec6) [decision, below left =of dec4 -| dec3.south] {dec6};
\node (dec7) [decision, below right=of dec5 -| dec2.south] {dec7};
\node (box1) [startstop, right=of dec6] {box1};
\node (box2) [startstop, left =of dec7] {box2};
\node (box3) [startstop, below left =of dec6.center] {box3};
\node (box4) [startstop, below right=of dec6.center] {box4};
\node (box4) [startstop, below left =of dec7.center] {box5};
\node (box6) [startstop, below right=of dec7.center] {box6};

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.