Flowchart Diagram Alir
Flowchart Diagram Alir
1 Introduction
This tutorial document explains how to create flowcharts in LATEX using the pic
language developed by Brian W. Kernighan for typesetting graphics [1]. The
pic language provides an easy and flexible way to create procedural box-and-
arrow diagrams, state flow charts, circuit layouts and other drawings involving
repetitive uses of simple geometric forms and splines. The illustrations produced
with pic can be easily included in troff and LATEX documents. An important
advantage of using pic is that the figures are in vector form rather than bitmaps,
thus can be scaled and stored in compact files without altering the quality of
the graphs.
The purpose of this to quickly get you on the right track to producing
flowcharts that can be included in LATEX documents using. This document
is not intended to serve as a pic tutorial, but it provides references to the docu-
mentation where you may find elementary examples, sample pictures, and other
details that your are encouraged to check if you are unfamiliar with the pic
language.
1
dpic -p fig.pic > fig.tex
(b) Code containing tpic \special commands by executing the GNU pic
interpreter as follows:
gpic -t fig.pic > fig.tex
or
pic -t fig.pic > fig.tex
3. Depending on whether gpic or dpic were used in the previous step, include
fig.tex in your document respectively as follows:
(a) \begin{document}
...
\begin{figure}[htbp]
{
\input fig.tex
\centerline{\box\graph}
}
\caption{Figure title.}
\label{fig_label}
\end{figure}
...
\end{document}
(b) \begin{document}
\usepackage{pstricks}
...
\begin{figure}[htbp]
{
\centering
\input fig.tex
}
\caption{Figure title.}
\label{fig_label}
\end{figure}
...
\end{document}
2
The next sections briefly explain where to find the information and tools
to accomplish steps 1 and 2. Step 3 should be pretty straight forward as may
be seen from the source code for the inclusion of this document’s figures (see
file flowchart.tex).
3
There is no point in repeating the good explanations found in these references.
If you are unfamiliar with pic and cannot figure out the meaning of the drawing
commands in the *.pic files provided as examples with this document, you
should read the references in the order in which they have been listed to get a
good basis of pic’s capabilities and functionality.
Creating flowcharts with pic is not much different to the process of making
a figure with pic. To facilitate the task of making flowcharts, a set of macros
for the standard flowchart symbols was created (see Appendix A or the *.pic
files for details on the macro definitions). In order to make your own flowcharts
you must copy the macros from any of the *.pic files to a new file and write
your code right after the macros. Do not forget to end your code with the .PE
pic command. The structure of your pic file should look like:
.PE
The macros receive as arguments the scaling factors for the horizontal (sx)
and vertical (sy) dimension of the symbol. Only the connector symbol receives
one scaling factor (s) because it is a circle. The scaling factors multiply the
basic unit length defined for the macros as parameter csize (cell size). For
example, a symbol which is 12 × 8 units or cells and that has been declared with
sx set to 2, sy set to 4, will be 24 × 32 units big. By default the cell size value
is set to 2 mm, therefore, the scaled symbol will actually measure 48 × 64 mm.
The available macros are:
4
• keying(sx,sy): makes a block to represent a process or operation that in-
volves typing or is driven by some manual input device (“flat fat sausage”
block).
• keyboard(sx,sy): makes a block to represent a keyboard, switches or push-
buttons (quadrilateral block).
• document(sx,sy): makes a document symbol (rectangle with wavy line at
the bottom).
• display(sx,sy): makes a display symbol to represent a computer screen or
monitor, video devices, console printers, or other visual indicators.
The symbols produced by these macros are shown in the figure 1, which was
created with the following lines of code (see file flow0.pic):
down;
C0: connector(1);
arrow;
H0: preparation(1,1); "\sf Preparation" at H0.c;
move to H0.B.s;
arrow;
D0: data(1,1); "\sf Data" at D0.c;
move to D0.B.s;
arrow;
P0: process(1,1); "\sf Process" at P0.c;
move to P0.B.s;
arrow;
R0: decision(1,1); "\sf Decision" at R0.c;
move to R0.B.s;
arrow;
T0: terminator(1,1); "\sf Terminator" at T0.c;
move to R0.B.w;
left;
arrow;
K0: keying(1,1); "\sf Keying" at K0.c;
move to K0.B.w;
arrow invis;
K1: keyboard(1,1); "\sf Keyboard" at K1.c;
move to K1.B.e;
right;
arrow;
move to K0.B.n;
line -> dashed up C0.w.y-K0.n.y then right C0.w.x-K0.n.x;
move to P0.B.e;
5
right;
arrow;
W0: document(1,1); "\sf Document" at W0.c;
move to D0.B.e;
right;
arrow;
S0: display(1,1); "\sf Display" at S0.c;
It is to be noted that the sizing of the symbols was made according to the
IBM flowcharting template [6], in which most symbols are 12 × 8 units long and
should also match those of the ISO standard [7]. Practically any flowchart can
be prepared with these symbols. As a matter of fact, the basic blocks: process,
data, connector, together with the processing and sequencing symbols: decision,
preparation, terminator, should be sufficient for most flowcharting needs. The
input/output and processing hardware related symbols can be replaced for data
blocks without losx of clarity, as far as the data flow or algorithmic description
are concerned.
Additional examples on the use of the macros are presented in the next
subsections. For further information and references about flowcharts please
check also [8] and references therein.
#If-Then-Else
I1: [arrow;
R1: decision(1,1); "\sf Decision" at R1.c;
move to R1.s;
arrow;
6
Preparation
Data Display
Process Document
Terminator
7
P1: process(1,1); "\sf Process 1" at P1.c;
move to P1.B.s;
L1: line;
move to R1.e; line -> right 20 then down R1.e.y-P1.n.y;
P2: process(1,1); "\sf Process 2" at P2.c;
move to P2.B.s;
line -> down P2.s.y-L1.end.y then left P2.s.x-L1.end.x;
down;arrow;box invis "{\Large {\sf If-Then-Else}}";
]
move to I1.s-(0,5);
#While-Do
W1: [L1: line;
arrow;
R1: decision(1,1); "\sf Decision" at R1.c;
move to R1.s;
arrow;
box invis "{\Large {\sf While-Do}}";
move to R1.e;
right;arrow;
P1: process(1,1); "\sf Process X" at P1.c;
move to P1.n;
line -> up L1.end.y-P1.n.y then left P1.n.x-L1.end.x;
]
8
Decision
Process B
If-Then-Else
Process C
While-Do
9
move to R3.s;
arrow;
PD: process(1,1); "\sf Default" "\sf Process" at PD.c;
move to PD.s;
L1: line;
move to R1.e;
right;arrow;
P1: process(1,1); "\sf Process 1" at P1.c;
move to P1.e;
P1A: arrow;
move to R2.e;
right;arrow;
P2: process(1,1); "\sf Process 2" at P2.c;
move to P2.e;
arrow;
move to R3.e;
right;arrow;
P3: process(1,1); "\sf Process 3" at P3.c;
move to P3.e;
arrow;
move to P1A.end;
line -> down P1A.end.y-L1.end.y then left P1A.end.x-L1.end.x;
down;arrow;box invis "{\Large {\sf Case-Of}}";
]
move to CS1.ne+(40,-35);
#Do-Until
DU1: [L1: line;
arrow;
P1: process(1,1); "\sf Process" at P1.c;
move to P1.s;
arrow;
R1: decision(1,1); "\sf Decision" at R1.c;
move to R1.s;
arrow;
box invis "{\Large {\sf Do-Until}}";
move to R1.e;
line -> right 20 then up L1.end.y-R1.e.y then left R1.e.x+20-L1.end.x;
]
10
Decision 1 Process 1
Decision 2 Process 2
Process
Decision 3 Process 3
Decision
Default
Process
Do-Until
Case-Of
11
different classes’ reference feature vector fc . The two outer for-from-to-do
loops correspond to the pixel position, while the inner loop corresponds to
the testing with respect to each class c. This algorithm can be describe in
terms of the flowchart shown in fig. 4. In this flowchart example, the two outer
for-from-to-do loops have been represented by a single for-from-to-do loop
over the pixel position p.
12
&imgaux←&img;
p ← (0, 0)
no p ∈ DI
yes
Compute
feature vector
f (p)
c=0
no c < N
classes
yes
no kf (p) − fc k < λ
yes
&img(p)=0 &img(p)=c
Increment
class
c←c+1
Update
position
p ← p + ∆p
End
13
Figure 4: Flowchart for a color-based image segmentation process.
The code that generates de flowchart in fig. 4 is (see file flowcs.pic):
C0: connector(crad);
arrow alen;
P0a: process(1,0.8);
"\parbox{6em}{\centering \sf \small Compute\\
feature vector\\ $f(p)$}" at P0a.c;
move to P0a.B.s;
arrow alen;
C1: connector(crad);
arrow alen;
14
# check if the feature at pixel p, f(p) can be classified
# as the class c, due to the proximity with respect to
# the class feature vector f_c
R1a: decision(1,1);
"\parbox{7em}{\centering \sf
\footnotesize $\|f(p)-f_c\|<\lambda$}" at R1a.c;
move to R1a.B.w; "\sf no" above rjust;
move to R1a.B.s; "\sf yes" below ljust;
move to R1a.B.s;
arrow alen;
P1a: process(1,0.5);
"\parbox{6em}{\centering \sf \&img($p$)=$c$}" at P1a.c;
move to P1a.B.s;
down; arrow alen;
C1e: connector(0.1);
move to R1a.B.w;
left; line; line alen;
line -> down R1a.c.y-P1a.n.y;
P1b: process(1,0.5);
"\parbox{6em}{\centering \sf \&img($p$)=$0$}" at P1b.c;
move to P1b.B.s;
line -> down P1b.s.y-C1e.c.y then right to C1e.w;
move to C1e.s;
down; arrow alen;
P1: process(1,0.8);
"\parbox{6em}{\centering \sf Increment class\\
$c\leftarrow c+1$}" at P1.c;
move to P1.B.s;
L1a: line alen;
15
L1b: arrow down alen;
move to L1b.end;
down;
P0: process(1,0.8);
"\parbox{6em}{\centering \sf Update position\\
$p\leftarrow p+\Delta p$}" at P0.c;
T0: terminator(1,0.5);
"\parbox{6em}{\centering \sf End}" at T0.c;
16
(a) Using dpic [4]:
or with
Once the *.tex files are produced with any of the two previous methods,
the last step is to include them into your LATEX document according to the
corresponding approach, as explained in the third point of section 2 (see also
the source code of the examples provided with this document).
References
[1] B. W. Kernighan. PIC – A Graphics Language for Type-
setting (Revised User Manual) Bell Labs Computing Sci-
ence Technical Report #116, December 1991. Available at:
http://www.cs.bell-labs.com/10thEdMan/pic.pdf.
[2] E. S. Raymond. Making pictures with GNU PIC, 1995. In GNUgroff source
distribution.
[3] J. D. Aplevich. M4 Macros for Electric Circuit Dia-
grams in LATEX Documents, version 6.4, 2008. Available at:
http://texcatalogue.sarovar.org/entries/circuit-macros.html or
the CTAN http://www.ctan.org mirrors.
[4] J. D. Aplevich. Dpic package, version 29 Oct. 2008. Available at:
http://www.ece.uwaterloo.ca/ aplevich/dpic/.
[5] Groff for Windows, version 1.19.2 Available at:
http://gnuwin32.sourceforge.net/packages/groff.htm. The package
homepage is: http://www.gnu.org/software/groff/groff.html.
17
[6] International Business Machines Corporation. IBM Flowchart-
ing Techniques. IBM Technical Publications Dept. Doc-
ument No. C20-8152-1, New York, 1069. Available at:
http://www.fh-jena.de/~ kleine/history/software/...
...IBM-FlowchartingTechniques-GC20-8152-1.pdf.
18
Appendix A pic Flowchart Macros
The macros implemented to produce the flowcharts in this document were de-
fined as pic language blocks. These blocks provide flowchart primitives by group-
ing into a single object or entity the lower level primitives of the pic language,
such as lines, boxes and arcs. Not surprisingly, the pic language primitives
grouped to form an object are called blocks in the terminology of the pic lan-
guage. The following code shows the implementation of the macros developed
to plot the flowchart symbols of the examples presented in this document. The
code of these macros should be included at the beginning of your own flowcharts
as explained in section 3.
19
line from B.ne to B.nw to B.sw to B.se to B.ne;
eshade;
#$3 at B.c;
]}
# data(): parallelogram -> "data input/output block"
define data
{[
w=$1*12*csize; h=$2*8*csize;
dx=(h/4)/2;
B: box wid w ht h invis;
sshade;
line from B.sw-(dx,0) to B.se-(dx,0) to B.ne+(dx,0)
to B.nw+(dx,0) to B.sw-(dx,0);
eshade;
#$3 at B.c;
]}
define connector
{[
r=$1*2*csize;
sshade;
B: circle rad r;
eshade;
#$3 at B.c;
]}
# decision(): rhomboid -> "if block"
define decision
{[
w=$1*12*csize; h=$2*8*csize;
B: box wid w ht h invis;
sshade;
line from B.n to B.e to B.s to B.w to B.n;
eshade;
#$3 at B.c;
]}
define preparation
{[
w=$1*12*csize; h=$2*8*csize;
dx=(h/2)/2;
B: box wid w ht h invis;
sshade;
line from B.w to B.nw+(dx,0) to B.ne-(dx,0) to B.e
to B.se-(dx,0) to B.sw+(dx,0) to B.w;
eshade;
#$3 at B.c;
]}
define terminator
20
{[
w=$1*12*csize; h=$2*4*csize;
r=h/2;
B: box wid w ht h invis;
sshade;
line from B.sw+(r,0) to B.se-(r,0);
right; arc rad r from Here to B.ne-(r,0);
line from Here to B.nw+(r,0);
left; arc rad r from Here to B.sw+(r,0);
eshade;
#$3 at B.c;
]}
define keying
{[
w=$1*14*csize; h=$2*8*csize;
dx=(h/4)/2;
r=dx/2+(h/2)^2/(2*dx);
B: box wid w ht h invis;
sshade;
line from B.sw+(dx,0) to B.se-(dx,0);
left; arc rad r from Here to B.ne-(dx,0);
line from Here to B.nw+(dx,0);
right; arc rad r from Here to B.sw+(dx,0);
eshade;
#$3 at B.c;
]}
define keyboard
{[
w=$1*12*csize; h=$2*5*csize;
dy=(w/6)/2;
B: box wid w ht h invis;
sshade;
line from B.nw-(0,dy) to B.sw to B.se
to B.ne+(0,dy) to B.nw-(0,dy);
eshade;
#$3 at B.c;
]}
define document
{[
w=$1*12*csize; h=$2*7*csize;
dy=(w/6)/2;
r=sqrt((w/2)^2+dy^2);
B: box wid w ht h invis;
sshade;
line from B.se+(0,dy) to B.ne to B.nw to B.sw;
up; arc rad w/2 from B.sw to B.s;
21
arc cw rad r from B.s to B.se+(0,dy);
eshade;
#$3 at B.c;
]}
define display
{[
w=$1*12*csize; h=$2*8*csize;
dx=1.5*(h/4)/2;
r=dx/2+(h/2)^2/(2*dx);
B: box wid w ht h invis;
sshade;
line from B.sw+(4*dx/1.5,0) to B.se-(dx,0);
left; arc rad r from Here to B.ne-(dx,0);
line from Here to B.nw+(4*dx/1.5,0);
arc rad r from Here to B.w;
right; arc rad r from Here to B.sw+(4*dx/1.5,0);
eshade;
#$3 at B.c;
]}
#--- END OF MACROS ---
22