Flowcharts in TikZ
Create professional flowcharts, process diagrams, and decision trees with TikZ.
Required Libraries
Load these libraries for flowchart creation:
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}Flowchart Node Styles
Define standard flowchart shapes:
\tikzset{
% Start/End (rounded rectangle or oval)
startstop/.style={
rectangle, rounded corners=10pt,
minimum width=2.5cm, minimum height=1cm,
draw, fill=red!20,
text centered
},
% Process (rectangle)
process/.style={
rectangle,
minimum width=2.5cm, minimum height=1cm,
draw, fill=blue!20,
text centered
},
% Decision (diamond)
decision/.style={
diamond, aspect=2,
minimum width=2.5cm, minimum height=1cm,
draw, fill=yellow!30,
text centered
},
% Input/Output (parallelogram)
io/.style={
trapezium, trapezium left angle=70, trapezium right angle=110,
minimum width=2.5cm, minimum height=1cm,
draw, fill=green!20,
text centered
},
% Arrow style
arrow/.style={
thick, ->, >=Stealth
}
}Simple Flowchart Example
\begin{tikzpicture}[node distance=1.5cm]
% Nodes
\node[startstop] (start) {Start};
\node[process, below=of start] (process1) {Process 1};
\node[decision, below=of process1] (decision1) {Condition?};
\node[process, below=of decision1] (process2) {Process 2};
\node[startstop, below=of process2] (stop) {End};
% Arrows
\draw[arrow] (start) -- (process1);
\draw[arrow] (process1) -- (decision1);
\draw[arrow] (decision1) -- node[right] {Yes} (process2);
\draw[arrow] (process2) -- (stop);
% Decision branch
\draw[arrow] (decision1) -- node[above] {No} ++(3,0) |- (process1);
\end{tikzpicture}Horizontal Flowchart
\begin{tikzpicture}[node distance=2cm, auto]
% Nodes arranged horizontally
\node[startstop] (start) {Start};
\node[process, right=of start] (input) {Input Data};
\node[process, right=of input] (process) {Process};
\node[process, right=of process] (output) {Output};
\node[startstop, right=of output] (end) {End};
% Connect with arrows
\draw[arrow] (start) -- (input);
\draw[arrow] (input) -- (process);
\draw[arrow] (process) -- (output);
\draw[arrow] (output) -- (end);
\end{tikzpicture}Flowchart with Multiple Branches
\begin{tikzpicture}[node distance=1.5cm]
\node[startstop] (start) {Start};
\node[io, below=of start] (input) {Input x};
\node[decision, below=of input] (dec1) {x > 0?};
% Left branch
\node[process, below left=1.5cm and 2cm of dec1] (positive) {x is positive};
% Right branch
\node[decision, below right=1.5cm and 2cm of dec1] (dec2) {x < 0?};
\node[process, below=of dec2] (negative) {x is negative};
\node[process, right=2cm of dec2] (zero) {x is zero};
% Merge point
\node[io, below=3cm of dec1] (output) {Output result};
\node[startstop, below=of output] (end) {End};
% Arrows
\draw[arrow] (start) -- (input);
\draw[arrow] (input) -- (dec1);
\draw[arrow] (dec1) -| node[near start, above] {Yes} (positive);
\draw[arrow] (dec1) -| node[near start, above] {No} (dec2);
\draw[arrow] (dec2) -- node[right] {Yes} (negative);
\draw[arrow] (dec2) -- node[above] {No} (zero);
\draw[arrow] (positive) |- (output);
\draw[arrow] (negative) |- (output);
\draw[arrow] (zero) |- (output);
\draw[arrow] (output) -- (end);
\end{tikzpicture}Loop Flowchart
\begin{tikzpicture}[node distance=1.5cm]
\node[startstop] (start) {Start};
\node[process, below=of start] (init) {i = 0};
\node[decision, below=of init] (check) {i < 10?};
\node[process, below=of check] (body) {Process i};
\node[process, below=of body] (inc) {i = i + 1};
\node[startstop, below right=1cm and 3cm of check] (end) {End};
% Main flow
\draw[arrow] (start) -- (init);
\draw[arrow] (init) -- (check);
\draw[arrow] (check) -- node[right] {Yes} (body);
\draw[arrow] (body) -- (inc);
% Loop back
\draw[arrow] (inc) -- ++(-3,0) |- (check);
% Exit loop
\draw[arrow] (check) -- node[above] {No} (end);
\end{tikzpicture}|- and -| for right-angle connections. The first character indicates the initial direction (vertical or horizontal).Subroutine/Function Call
\tikzset{
subroutine/.style={
rectangle,
minimum width=2.5cm, minimum height=1cm,
draw, fill=purple!20,
text centered,
path picture={
\draw (path picture bounding box.north west) ++(0.2,0) --
++(0,-1);
\draw (path picture bounding box.north east) ++(-0.2,0) --
++(0,-1);
}
}
}
\begin{tikzpicture}[node distance=1.5cm]
\node[startstop] (start) {Start};
\node[process, below=of start] (prep) {Prepare data};
\node[subroutine, below=of prep] (sub) {Call function()};
\node[process, below=of sub] (use) {Use result};
\node[startstop, below=of use] (end) {End};
\draw[arrow] (start) -- (prep);
\draw[arrow] (prep) -- (sub);
\draw[arrow] (sub) -- (use);
\draw[arrow] (use) -- (end);
\end{tikzpicture}Swimlane Flowchart
\begin{tikzpicture}
% Swimlane backgrounds
\fill[blue!10] (0,0) rectangle (3,-8);
\fill[green!10] (3,0) rectangle (6,-8);
\fill[orange!10] (6,0) rectangle (9,-8);
% Swimlane headers
\node[font=\bfseries] at (1.5,0.5) {User};
\node[font=\bfseries] at (4.5,0.5) {System};
\node[font=\bfseries] at (7.5,0.5) {Database};
% Divider lines
\draw[thick] (3,1) -- (3,-8);
\draw[thick] (6,1) -- (6,-8);
% Nodes in swimlanes
\node[process, minimum width=2cm] (login) at (1.5,-1.5) {Login};
\node[process, minimum width=2cm] (validate) at (4.5,-3) {Validate};
\node[process, minimum width=2cm] (query) at (7.5,-4.5) {Query};
\node[process, minimum width=2cm] (respond) at (4.5,-6) {Respond};
\node[process, minimum width=2cm] (display) at (1.5,-7.5) {Display};
% Arrows crossing lanes
\draw[arrow] (login) -- (validate);
\draw[arrow] (validate) -- (query);
\draw[arrow] (query) -- (respond);
\draw[arrow] (respond) -- (display);
\end{tikzpicture}Complete Algorithm Flowchart
Binary search algorithm as a flowchart:
\begin{tikzpicture}[node distance=1.2cm, font=\small]
\node[startstop] (start) {Start};
\node[io, below=of start] (input) {Input: array, target};
\node[process, below=of input] (init) {low=0, high=n-1};
\node[decision, below=of init] (while) {low <= high?};
\node[process, below=of while] (mid) {mid = (low+high)/2};
\node[decision, below=of mid] (compare) {arr[mid] == target?};
\node[io, right=3cm of compare] (found) {Return mid};
\node[decision, below=of compare] (less) {arr[mid] < target?};
\node[process, below left=1cm and 1.5cm of less] (higher) {low = mid+1};
\node[process, below right=1cm and 1.5cm of less] (lower) {high = mid-1};
\node[io, right=3cm of while] (notfound) {Return -1};
\node[startstop, below=4cm of less] (end) {End};
\draw[arrow] (start) -- (input);
\draw[arrow] (input) -- (init);
\draw[arrow] (init) -- (while);
\draw[arrow] (while) -- node[right] {Yes} (mid);
\draw[arrow] (mid) -- (compare);
\draw[arrow] (compare) -- node[above] {Yes} (found);
\draw[arrow] (compare) -- node[right] {No} (less);
\draw[arrow] (less) -| node[near start, above] {Yes} (higher);
\draw[arrow] (less) -| node[near start, above] {No} (lower);
\draw[arrow] (higher) |- ([yshift=5mm]while.west) -- (while);
\draw[arrow] (lower) |- ([yshift=5mm]while.west);
\draw[arrow] (while) -- node[above] {No} (notfound);
\draw[arrow] (found) |- (end);
\draw[arrow] (notfound) |- (end);
\end{tikzpicture}Next Steps
Continue learning TikZ diagrams:
- Block Diagrams - System architecture diagrams
- Trees - Hierarchical structures
- Graphs - Network diagrams
Flowcharts in TikZ
Create professional flowcharts, process diagrams, and decision trees with TikZ.
Required Libraries
Load these libraries for flowchart creation:
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}Flowchart Node Styles
Define standard flowchart shapes:
\tikzset{
% Start/End (rounded rectangle or oval)
startstop/.style={
rectangle, rounded corners=10pt,
minimum width=2.5cm, minimum height=1cm,
draw, fill=red!20,
text centered
},
% Process (rectangle)
process/.style={
rectangle,
minimum width=2.5cm, minimum height=1cm,
draw, fill=blue!20,
text centered
},
% Decision (diamond)
decision/.style={
diamond, aspect=2,
minimum width=2.5cm, minimum height=1cm,
draw, fill=yellow!30,
text centered
},
% Input/Output (parallelogram)
io/.style={
trapezium, trapezium left angle=70, trapezium right angle=110,
minimum width=2.5cm, minimum height=1cm,
draw, fill=green!20,
text centered
},
% Arrow style
arrow/.style={
thick, ->, >=Stealth
}
}Simple Flowchart Example
\begin{tikzpicture}[node distance=1.5cm]
% Nodes
\node[startstop] (start) {Start};
\node[process, below=of start] (process1) {Process 1};
\node[decision, below=of process1] (decision1) {Condition?};
\node[process, below=of decision1] (process2) {Process 2};
\node[startstop, below=of process2] (stop) {End};
% Arrows
\draw[arrow] (start) -- (process1);
\draw[arrow] (process1) -- (decision1);
\draw[arrow] (decision1) -- node[right] {Yes} (process2);
\draw[arrow] (process2) -- (stop);
% Decision branch
\draw[arrow] (decision1) -- node[above] {No} ++(3,0) |- (process1);
\end{tikzpicture}Horizontal Flowchart
\begin{tikzpicture}[node distance=2cm, auto]
% Nodes arranged horizontally
\node[startstop] (start) {Start};
\node[process, right=of start] (input) {Input Data};
\node[process, right=of input] (process) {Process};
\node[process, right=of process] (output) {Output};
\node[startstop, right=of output] (end) {End};
% Connect with arrows
\draw[arrow] (start) -- (input);
\draw[arrow] (input) -- (process);
\draw[arrow] (process) -- (output);
\draw[arrow] (output) -- (end);
\end{tikzpicture}Flowchart with Multiple Branches
\begin{tikzpicture}[node distance=1.5cm]
\node[startstop] (start) {Start};
\node[io, below=of start] (input) {Input x};
\node[decision, below=of input] (dec1) {x > 0?};
% Left branch
\node[process, below left=1.5cm and 2cm of dec1] (positive) {x is positive};
% Right branch
\node[decision, below right=1.5cm and 2cm of dec1] (dec2) {x < 0?};
\node[process, below=of dec2] (negative) {x is negative};
\node[process, right=2cm of dec2] (zero) {x is zero};
% Merge point
\node[io, below=3cm of dec1] (output) {Output result};
\node[startstop, below=of output] (end) {End};
% Arrows
\draw[arrow] (start) -- (input);
\draw[arrow] (input) -- (dec1);
\draw[arrow] (dec1) -| node[near start, above] {Yes} (positive);
\draw[arrow] (dec1) -| node[near start, above] {No} (dec2);
\draw[arrow] (dec2) -- node[right] {Yes} (negative);
\draw[arrow] (dec2) -- node[above] {No} (zero);
\draw[arrow] (positive) |- (output);
\draw[arrow] (negative) |- (output);
\draw[arrow] (zero) |- (output);
\draw[arrow] (output) -- (end);
\end{tikzpicture}Loop Flowchart
\begin{tikzpicture}[node distance=1.5cm]
\node[startstop] (start) {Start};
\node[process, below=of start] (init) {i = 0};
\node[decision, below=of init] (check) {i < 10?};
\node[process, below=of check] (body) {Process i};
\node[process, below=of body] (inc) {i = i + 1};
\node[startstop, below right=1cm and 3cm of check] (end) {End};
% Main flow
\draw[arrow] (start) -- (init);
\draw[arrow] (init) -- (check);
\draw[arrow] (check) -- node[right] {Yes} (body);
\draw[arrow] (body) -- (inc);
% Loop back
\draw[arrow] (inc) -- ++(-3,0) |- (check);
% Exit loop
\draw[arrow] (check) -- node[above] {No} (end);
\end{tikzpicture}|- and -| for right-angle connections. The first character indicates the initial direction (vertical or horizontal).Subroutine/Function Call
\tikzset{
subroutine/.style={
rectangle,
minimum width=2.5cm, minimum height=1cm,
draw, fill=purple!20,
text centered,
path picture={
\draw (path picture bounding box.north west) ++(0.2,0) --
++(0,-1);
\draw (path picture bounding box.north east) ++(-0.2,0) --
++(0,-1);
}
}
}
\begin{tikzpicture}[node distance=1.5cm]
\node[startstop] (start) {Start};
\node[process, below=of start] (prep) {Prepare data};
\node[subroutine, below=of prep] (sub) {Call function()};
\node[process, below=of sub] (use) {Use result};
\node[startstop, below=of use] (end) {End};
\draw[arrow] (start) -- (prep);
\draw[arrow] (prep) -- (sub);
\draw[arrow] (sub) -- (use);
\draw[arrow] (use) -- (end);
\end{tikzpicture}Swimlane Flowchart
\begin{tikzpicture}
% Swimlane backgrounds
\fill[blue!10] (0,0) rectangle (3,-8);
\fill[green!10] (3,0) rectangle (6,-8);
\fill[orange!10] (6,0) rectangle (9,-8);
% Swimlane headers
\node[font=\bfseries] at (1.5,0.5) {User};
\node[font=\bfseries] at (4.5,0.5) {System};
\node[font=\bfseries] at (7.5,0.5) {Database};
% Divider lines
\draw[thick] (3,1) -- (3,-8);
\draw[thick] (6,1) -- (6,-8);
% Nodes in swimlanes
\node[process, minimum width=2cm] (login) at (1.5,-1.5) {Login};
\node[process, minimum width=2cm] (validate) at (4.5,-3) {Validate};
\node[process, minimum width=2cm] (query) at (7.5,-4.5) {Query};
\node[process, minimum width=2cm] (respond) at (4.5,-6) {Respond};
\node[process, minimum width=2cm] (display) at (1.5,-7.5) {Display};
% Arrows crossing lanes
\draw[arrow] (login) -- (validate);
\draw[arrow] (validate) -- (query);
\draw[arrow] (query) -- (respond);
\draw[arrow] (respond) -- (display);
\end{tikzpicture}Complete Algorithm Flowchart
Binary search algorithm as a flowchart:
\begin{tikzpicture}[node distance=1.2cm, font=\small]
\node[startstop] (start) {Start};
\node[io, below=of start] (input) {Input: array, target};
\node[process, below=of input] (init) {low=0, high=n-1};
\node[decision, below=of init] (while) {low <= high?};
\node[process, below=of while] (mid) {mid = (low+high)/2};
\node[decision, below=of mid] (compare) {arr[mid] == target?};
\node[io, right=3cm of compare] (found) {Return mid};
\node[decision, below=of compare] (less) {arr[mid] < target?};
\node[process, below left=1cm and 1.5cm of less] (higher) {low = mid+1};
\node[process, below right=1cm and 1.5cm of less] (lower) {high = mid-1};
\node[io, right=3cm of while] (notfound) {Return -1};
\node[startstop, below=4cm of less] (end) {End};
\draw[arrow] (start) -- (input);
\draw[arrow] (input) -- (init);
\draw[arrow] (init) -- (while);
\draw[arrow] (while) -- node[right] {Yes} (mid);
\draw[arrow] (mid) -- (compare);
\draw[arrow] (compare) -- node[above] {Yes} (found);
\draw[arrow] (compare) -- node[right] {No} (less);
\draw[arrow] (less) -| node[near start, above] {Yes} (higher);
\draw[arrow] (less) -| node[near start, above] {No} (lower);
\draw[arrow] (higher) |- ([yshift=5mm]while.west) -- (while);
\draw[arrow] (lower) |- ([yshift=5mm]while.west);
\draw[arrow] (while) -- node[above] {No} (notfound);
\draw[arrow] (found) |- (end);
\draw[arrow] (notfound) |- (end);
\end{tikzpicture}Next Steps
Continue learning TikZ diagrams:
- Block Diagrams - System architecture diagrams
- Trees - Hierarchical structures
- Graphs - Network diagrams