This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchap-design.tex
425 lines (343 loc) · 17.5 KB
/
chap-design.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
\chapter{Figures, Tables, Equations, Algorithms, etc}\label{chap:design}
%Your design chapter. I probably should include some examples on inserting figures, tables, mathematical equations, etc.
(This is supposed to be the design or methodology chapter. Instead, we include examples on inserting figures, tables, mathematical equations\ldots i.e.\ things that you might want to include in your thesis.)
\section{Inserting Figures}\label{sec:figure}
You can draw diagrams with special \LaTeX\ commands, but this may take some extra time to learn. I've had some forays into the \texttt{pgf} and \texttt{tikz} packages and must say I quite like the results; but as I said, they take time to learn. If you want a faster solution, you can draw your diagrams using other applications, and saving them as graphic files (EPS, PNG, JPG, PDF).
\LaTeX{} requires EPS (encapsulated postscript) graphic files when generating DVI output, and PNG, JPG or PDF when generating PDF output.
For exporting to EPS, try \url{http://www.cloudconvert.com}. It's like a Swiss knife for converting from almost any format, to almost any format.
Do note that IPS \textbf{discourages} the use of colours in your thesis, including diagrams and figures. Phographs and colour plates are exceptions to this rule: see Section~\ref{sec:plate}.
Here's how to insert a picture with the filename \verb|pythag.eps| or \verb|pythag.png|. I'm going to display it here with 5cm width, and the caption ``Pythagoras' Theorem''.
\begin{figure}[hbt!]
\begin{lstlisting}
\begin{figure}[hbt!]\centering
\includegraphics[width=50mm]{pythag}
\caption{Pythagoras' Theorem}\label{fig:pythagoras}
\end{figure}
\end{lstlisting}
\caption{Including a Graphics File}\label{fig:lst:graphics}
\end{figure}
The result would be:
\begin{figure}[hbt!]\centering
\includegraphics[width=50mm]{pythag}
\caption{Pythagoras' Theroem} \label{fig:pythagoras}
\end{figure}
Don't specify the extension of the graphic file. The template will automatically look for the EPS or the PNG (or otherwise) versions, depending on whether \verb|latex| or \verb|pdflatex| was used. The \texttt{figure} environment will also ensure that that an entry is inserted into the \emph{List of Figures} automatically -- including the figure numbering, caption and page number.
In addition, the width of the included graphics can also be specified as a percentage of the text width, e.g.~ \verb|width=.2\textwidth| would cause the graphics to occupy 20\% of the text width.
Notice that I inserted a \verb|\label| just after the \verb|\caption|. This can be used for referencing the figure number, like this: \\
\verb|Figure \ref{fig:pythagoras}| $\to$ Figure \ref{fig:pythagoras}
This works the same for chapters, sections, tables, equations too. In \verb|chap-intro.tex|, I labelled the Introduction chapter with \verb|\label{chap:intro}|. I also labelled the section on inserting figures, \verb|\label{sec:figure}|. So now I can do \\
\verb|Chapter \ref{chap:intro}| $\to$ Chapter \ref{chap:intro} \\
\verb|section \ref{sec:figure}| $\to$ section \ref{sec:figure}
Everytime the numbering of the heading changes, the reference will change automatically as well. \textbf{This is another advantage of using \LaTeX{}}: you do not need to manually update the reference counters (nor the Table of Contents, List of Figures and Tables) whenever you add or remove figures, tables, sections or chapters.
You might also want to try out \texttt{JpgfDraw}: it is a vector graphics and drawing application (requiring Java), and can export to \LaTeX{} code which you can paste into your \LaTeX{} source. \texttt{JpgfDraw} is available from \url{http://theoval.cmp.uea.ac.uk/~nlct/jpgfdraw/index.html}.
\section{How Do I Do Subfigures?}
Here's an example on how to do subfigures (and similarly subtables):
\begin{figure}[hbt!]
\begin{lstlisting}
\begin{figure}[hbt!]
\begin{minipage}{.49\textwidth}
\centering
\subfloat[First caption]{\includegraphics[width=3cm]{pythag}} \label{fig:sub1}
\end{minipage}
\hfill
\begin{minipage}{.49\textwidth}
\subfloat[Second caption]{\includegraphics[width=0.8\textwidth]{USMScience}}\label{fig:sub2}
\end{minipage}
\caption{This is the main caption of the figure.}
\label{fig:main}
\end{figure}
\end{lstlisting}
\caption{Creating subfigures within figures}
\end{figure}
\begin{figure}[hbt!]
\begin{minipage}{.49\textwidth}
\centering
\subfloat[First caption]{\includegraphics[width=3cm]{pythag}} \label{fig:sub1}
\end{minipage}
\hfill
\begin{minipage}{.49\textwidth}
\subfloat[Second caption]{\includegraphics[width=0.8\textwidth]{USMScience}}\label{fig:sub2}
\end{minipage}
\caption{This is the main caption of the figure.}
\label{fig:main}
\end{figure}
\section{Inserting Plates}\label{sec:plate}
Colour photographs are now regarded as \emph{plates}. They must be listed in the \emph{List of Plates} instead of the List of Figures, and should be printed in colour on glossy photo paper \citep{ips:thesis:guideline:2007}.
The \texttt{usmthesis} document class defines a new \texttt{plate} environment, as well as a corresponding \verb|\listofplates| command. (The \verb|\listofplates| command is already placed in the sample template file \verb|usmthesis.tex|.) In short, all you need to do to insert a photograph or plate (as a graphics file \verb|USMScience.{eps,png,jpg}|) is shown in Figure~\ref{fig:lst:plate}, and you will then get Plate~\ref{plate:ppsk:usm} as the result.
\begin{figure}[hbt!]
\begin{lstlisting}
\begin{plate}[hbt!]\centering
\includegraphics[width=.9\textwidth]{USMScience}
\caption{School of Computer Sciences, USM}\label{plate:ppsk:usm}
\end{plate}
\end{lstlisting}
\caption{Inserting a Plate}\label{fig:lst:plate}
\end{figure}
\begin{plate}[hbt!]\centering
\includegraphics[width=.9\textwidth]{USMScience}
\caption{School of Computer Sciences, USM}\label{plate:ppsk:usm}
\end{plate}
\section{Inserting Tables}
Typesetting tables can be a little troublesome especially with complex layouts. Look up \citep{roberts} to learn about some tips, or you can use the \textrm{LaTable} program (\url{http://www.g32.org/latable/}) to help you.
If using \textrm{LaTable}, when you're done designing the table, copy the whole table as \LaTeX\ code, and paste it in your source file. (You may add additional formatting commands, like bold, italics, etc.) If this is going to be a numbered table, remember to surround it with \verb|\begin{table}| and \verb|\end{table}|, and give it a caption, like this:
\begin{figure}[hbt!]
\begin{lstlisting}
\begin{table}[hbt!]\centering
\begin{tabular}{| l | c || r |}
\hline
\textbf{Name} & \textbf{Category} & \textbf{Quantity} \\
\hline\hline
Apple & Fruit & 10 \\
\hline
Cucumber & Vegetable & 25 \\
\hline
Daisy & Flower & 5 \\
\hline
\end{tabular}
\caption{Sample Table Only} \label{table:sample}
\end{table}
\end{lstlisting}
\caption{Typesetting Tables}\label{fig:lst:table}
\end{figure}
\begin{table}[hbt!]\centering
\begin{tabular}{| l | c || r |}
\hline
\textbf{Name} & \textbf{Category} & \textbf{Quantity} \\
\hline\hline
Apple & Fruit & 10 \\
\hline
Cucumber & Vegetable & 25 \\
\hline
Daisy & Flower & 5 \\
\hline
\end{tabular}
\caption{Sample Table Only} \label{table:sample}
\end{table}
Note also that \verb|usmthesis| is configured such that captions for figures are placed \emph{below} the figures, and captions for tables are placed \emph{above} them, in accordance with the formatting guidelines.
Many of us would have had massive headaches about lining up decimal places in table columns (as mentioned in the IPS guidelines) if not for this tip from \citep[pp.~274--276]{latex:companion}. This method uses the \verb|dcolumn| package (already loaded by \verb|usmthesis.cls|). Instead of using \verb|l,c| or \verb|r| as the column type in the \verb|tabular| declaration, use\\ \texttt{D\{\textit{input sep}\}\{\textit{output sep}\}\{\textit{decimal places}\}}.
\begin{figure}[htb!]
\begin{lstlisting}
\begin{table}[htb!]\centering
\begin{tabular}{| c | D{.}{.}{2} |}
\hline
Item & \multicolumn{1}{c|}{Reading}\\\hline
A & 1.11\\\hline
B & 3.99\\\hline
C & 2.27\\\hline
\end{tabular}
\caption{A table with decimal data}
\end{table}
\end{lstlisting}
\caption{Aligning decimal data in tables}\label{fig:align:decimal}
\end{figure}
The \LaTeX\ code in Figure~\ref{fig:align:decimal} will give you Table~\ref{tab:align:decimal}.
\begin{table}[htb!]\centering
\begin{tabular}{| c | D{.}{.}{3} |}
\hline
Item & \multicolumn{1}{c|}{Reading}\\\hline
A & 1.11\\\hline
B & 3.999\\\hline
C & 22.2\\\hline
\end{tabular}
\caption{A table with decimal data}\label{tab:align:decimal}
\end{table}
Without using \verb|dcolumn|, you'd get something like this:
\begin{table}[htb!]\centering
\begin{tabular}{| c | r |}
\hline
Item & \multicolumn{1}{c|}{Reading}\\\hline
A & 1.11\\\hline
B & 3.999\\\hline
C & 22.2\\\hline
\end{tabular}
\caption{A table with decimal data (mis-aligned)}
\end{table}
\section{Full-paged, Sideways Figures and Tables}
To make a figure appear on a landscape, full-page layout, put your \verb|\includegraphics| command in a \verb|sidewaysfigure| environment (Figure~\ref{fig:lst:sidewayfigure}).
\begin{figure}[htb!]
\begin{lstlisting}
\begin{sidewaysfigure}\centering
\includegraphics[width=\textheight]{latex-win-comp}
\caption{A full-page, sideways figure}\label{fig:sidewaysfig}
\end{sidewaysfigure}
\end{lstlisting}
\caption{Including a sideway, full-page graphic}\label{fig:lst:sidewayfigure}
\end{figure}
\begin{sidewaysfigure}
\centering\includegraphics[width=\textheight]{latex-win-comp}
\caption{A full-page, sideways figure}\label{fig:sidewaysfig}
\end{sidewaysfigure}
The resultant figure (Figure~\ref{fig:sidewaysfig}) should appear on the next page.
For a sideways table, use the \verb|sidewaystable| environment instead around your usual \verb|tabular| material.
\section{Mathematical Equations}
%Oooh I love this one. After all, maths is the reason why Donald Knuth created \TeX{}! It would be quite impossible for me to list all the commands, so I'll just give some example here, and you're better off looking at the various online tutorials like \cite{roberts}. And TeXnicCenter certainly makes things much easier.
Typesetting mathematical material is one of, if not \emph{the}, strongest capabilities of \LaTeX. After all, that was the Knuth's main motivation for creating \TeX{}. As it is impossible to enumerate all possible mathematically-related commands and macros here, we will just give some examples. The reader is directed to the many well-written online tutorials, such as \citep{roberts}, for more elaborate examples. TeXnicCenter also provides many shortcut buttons for inserting mathematical symbols.
\begin{figure}[htb!]
\begin{lstlisting}
\begin{equation}\label{eq:pythagoras}
z^2 = x^2 + y^2
\end{equation}
\begin{equation}\label{eq:golden:ratio}
\phi = \frac{1}{2} (1 + \sqrt{5})
\end{equation}
\begin{equation}\label{eq:golden:ratio}
\phi = \frac{1}{2} (1 + \sqrt{5})
\end{equation}
\begin{equation}\label{eq:golden:ratio:fibonacci}
\phi = 1 + \sum ^ {\infty} _ {n=1}
\frac{ (-1) ^ {n+1} }{ F_n F_{n+1} }
\end{equation}
Equation~\ref{eq:pythagoras} is the Pythagoras Theorem.
\eqref{eq:golden:ratio} gives the golden ratio $\phi$, and
\eqref{eq:golden:ratio:fibonacci} relates it to the Fibonacci
series.
\end{lstlisting}
\caption{Typesetting Mathematical Equations}\label{fig:lst:equation}
\end{figure}
\begin{equation}\label{eq:pythagoras}
z^2 = x^2 + y^2
\end{equation}
\begin{equation}\label{eq:golden:ratio}
\phi = \frac{1}{2} (1 + \sqrt{5})
\end{equation}
\begin{equation}\label{eq:golden:ratio:fibonacci}
\phi = 1 + \sum ^ {\infty} _ {n=1}
\frac{ (-1) ^ {n+1} }{ F_n F_{n+1} }
\end{equation}
Equation~\ref{eq:pythagoras} is the Pythagoras Theorem. \eqref{eq:golden:ratio} gives the golden ratio $\phi$, and \eqref{eq:golden:ratio:fibonacci} relates it to the Fibonacci series.
The \LaTeX\ code to generate the above mathematics materials are shown in Figure~\ref{fig:lst:equation}. As you can see, references to equations can be achieved with either \verb|\ref| or \verb|\eqref|.
A disclaimer: if you think the mathematic equations don't look as great as all those \LaTeX\ advocates make them out to be, that's because IPS requires Times to be used and the current offerings of free \LaTeX\ math fonts for Times don't look great. It would've been a different picture if we used Computer Modern.
\section{Acronyms}
\acresetall
If you have a list of acronyms or symbols, edit the file \verb|loa.tex| as in Figure~\ref{fig:acronym}.
\begin{figure}[hbt!]
\begin{lstlisting}
\begin{acronym}[UTMK] %% replace 'UTMK' with the longest acronym in your list
\acro{IPS}{Institut Pengajian Siswazah}
\acro{PPSK}{Pusat Pengajian Sains Komputer}
\acro{USM}{Universiti Sains Malaysia}
\acro{UTMK}{Unit Terjemahan Melalui Komputer}
\end{acronym}
\end{lstlisting}
\caption{The template \texttt{loa.tex} for acronyms}\label{fig:acronym}
\end{figure}
You can also use this acronym list to help expand it the first time you mention it in your text. For example, the first time you use \verb|\ac{USM}|, `\ac{USM}' will be the output (without the quotes). After that, all calls to \verb|\ac{USM}| will give `\ac{USM}' (without the quotes). For more information, see the documentation for the \texttt{acronym} package.
% Please feel free to use whatever package you like for typesetting algorithms!
\section{Typesetting Algorithms}
As computer scientists, it is quite common to include algorithms and/or pseudocode. There are a number of different packages available, but unfortunately they tend not to work well together! I'm using \texttt{algorithmicx} here.
\begin{figure}[hbt!]
\begin{lstlisting}
\begin{algorithm}[hbt!]
\begin{algorithmic}
\Require $n \geq 0$
\Ensure $y = x^n$
\State $y \Leftarrow 1$
\State $X \Leftarrow x$
\State $N \Leftarrow n$
\While{$N \neq 0$}
\If{$N$ is even}
\State $X \Leftarrow X \times X$
\State $N \Leftarrow \frac{N}{2} $ \Comment{This is a comment}
\ElsIf{$N$ is odd}
\State $y \Leftarrow y \times X$
\State $N \Leftarrow N - 1$
\EndIf
\EndWhile
\end{algorithmic}
\caption{Computing $x^n, n > 0$}
\end{algorithm}
\end{lstlisting}
\caption{Typesetting Algorithms}\label{fig:lst:algo}
\end{figure}
\begin{algorithm}[hbt!]
\begin{algorithmic}
\Require $n \geq 0$
\Ensure $y = x^n$
\State $y \Leftarrow 1$
\State $X \Leftarrow x$
\State $N \Leftarrow n$
\While{$N \neq 0$}
\If{$N$ is even}
\State $X \Leftarrow X \times X$
\State $N \Leftarrow \frac{N}{2} $ \Comment{This is a comment}
\ElsIf{$N$ is odd}
\State $y \Leftarrow y \times X$
\State $N \Leftarrow N - 1$
\EndIf
\EndWhile
\end{algorithmic}
\caption{Computing $x^n, n > 0$}
\end{algorithm}
\section{Program Listings}
You may have noticed that I used the \verb|lstlisting| environment to typeset some of the \LaTeX{} examples -- with pretty-printing\footnote{Whether you agree that it \emph{is} pretty is another story altogether.}, too, including automatic line-breaking. For more information, see the documentation for the \verb|listings| package: it's available online at \url{http://www.texdoc.net/pkg/listings}.
Just to give some simple example here. For example, to typeset a ``Hello World'' Java program with syntax highlighting, you can use the following code:
\begin{figure}[hbt!]
\begin{lstlisting}[escapechar=:,language={}]
\lstset{basicstyle=\small\ttfamily, language=Java, breaklines=true, columns=fullflexible, tabsize=2}
\begin{lstlisting}
public class HelloWorld {
public static void main( String arg[] ) {
for (int i = 0; i < 10; i++) {
System.out.println( "Hello World!" + i);
}
}
}
\end:\{:lstlisting:\}:
\end{lstlisting}
\caption{Typesetting a Java program listing}\label{fig:lst:syntax}
\end{figure}
\lstset{keywordstyle={\bfseries}}
\begin{figure}[hbt!]
\lstset{basicstyle=\small\ttfamily, language=Java, breaklines=true, columns=fullflexible, framesep=10pt, xleftmargin=16pt, tabsize=2}
\begin{lstlisting}
public class HelloWorld {
public static void main( String arg[] ) {
for (int i = 0; i < 10; i++) {
System.out.println( "Hello World!" + i);
}
}
}
\end{lstlisting}
\caption{A pretty-printed Java program listing with syntax highlighting}
\end{figure}
If you want to turn off the syntax highlighting, set \verb|language={}|. (See the \verb|listings| documentation for a list of programming languages for which syntax highlighting is supported.) You can also change the \verb|basicstyle| value to get different effects: e.g. a different font family, size or text formatting.
Here's another example for a C program:
\begin{figure}[hbt!]
\begin{lstlisting}[escapechar={:}, texcl=false,language={}]
\lstset{basicstyle=\sffamily, language=C, breaklines=true, columns=fullflexible, tabsize=2}
\begin{lstlisting}
int main() {
int c = 0;
c = c + 1;
printf( "%d", c );
return 0;
}
\end:\{:lstlisting:\}:
\end{lstlisting}
\caption{Typesetting a C program listing}\label{fig:lst:c}
\end{figure}
\begin{figure}[hbt!]
\lstset{basicstyle=\sffamily, language=C, breaklines=true, columns=fullflexible, framesep=10pt, xleftmargin=.4\textwidth, tabsize=4}
\begin{lstlisting}
int main() {
int c = 0;
c = c + 1;
printf( "%d", c );
return 0;
}
\end{lstlisting}
\caption{A pretty-printed C program listing with syntax highlighting}
\end{figure}
And here is the same C program listing \emph{without} syntax highlighting (by setting \verb|language={}|):
\begin{figure}[hbt!]
\lstset{basicstyle=\sffamily, language={}, breaklines=true, columns=fullflexible, framesep=10pt, xleftmargin=.4\textwidth, tabsize=4}
\begin{lstlisting}
int main() {
int c = 0;
c = c + 1;
printf( "%d", c );
return 0;
}
\end{lstlisting}
\caption{A C program listing without syntax highlighting}
\end{figure}