-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathch4_list_figure.tex
More file actions
377 lines (348 loc) · 19.8 KB
/
ch4_list_figure.tex
File metadata and controls
377 lines (348 loc) · 19.8 KB
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
\chapter{Various Special Structures in \LaTeX{}}
\paragraph{Introduction}
This chapter presents different special environments in \LaTeX{} apart from the display math mode and verbatim form previously, such as lists, figures, tables, and minipages.
\section{Lists}
\subsection{Unordered Lists}
\paragraph{Unordered Lists}
The ability to organize things into a \textit{list}\index{List} is essential in any documenting system. In \LaTeX{}, we can achieve this by using the \verb|itemize|\index{itemize@\texttt{itemize}} environment with the \texttt{\textbackslash item}\index{item@\texttt{\textbackslash item}} command. For example, if we write
\begin{lstlisting}
\begin{itemize}
\item Canada
\item Japan
\begin{itemize}
\item Tokyo
\item Kyoto
\end{itemize}
\item Korea
\begin{itemize}
\item Seoul
\item Pusan
\end{itemize}
\end{itemize}
\end{lstlisting}
then it will show up as
\begin{itemize}
\item Canada
\item Japan \begin{itemize}
\item Tokyo
\item Kyoto
\end{itemize}
\item Korea \begin{itemize}
\item Seoul
\item Pusan
\end{itemize}
\end{itemize}
Notice that the items are \textit{unordered/bulleted}\index{Unordered List} and the list can be \textit{nested}\index{Nested List}.
\subsection{Ordered Lists}
\paragraph{Numbered Lists}
Similarly, we can have an \textit{ordered/numbered}\index{Ordered List}\index{Numbered List} list by using the \verb|enumerate|\index{enumerate@\texttt{enumerate}} environment. For example, by typing
\begin{lstlisting}
\begin{enumerate}
\item A robot may not injure a human being ...
\item A robot must obey the orders given it by human ...
\item A robot must protect its own existence ...
\end{enumerate}
\end{lstlisting}
we acquire the following output:
\begin{enumerate}
\item A robot may not injure a human being or, through inaction, allow a human being to come to harm.
\item A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
\item A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
\end{enumerate}
It is also possible to have nested \verb|enumerate| groups.
\paragraph{Customizing Labels for Lists}
The \verb|enumitem|\index{enumitem@\texttt{enumitem}} package enhances the typesetting of lists. One of its prime utilities is to change the starting labels or bullets for every item by providing the \verb|label| option. For example,
\begin{lstlisting}
\begin{enumerate}[label=\alph*)]
\item Apple
\item Banana
\item Grape
\end{enumerate}
\end{lstlisting}
generates
\begin{enumerate}[label=\alph*)]
\item Apple
\item Banana
\item Grape
\end{enumerate}
There are other possible choices for \verb|label|, such as \texttt{\textbackslash arabic*}, \texttt{\textbackslash roman*}, \texttt{\textbackslash Roman*}, \texttt{\textbackslash Alph*}. Another usage of the \verb|enumitem| package is to make a continued list. For example, by ticking the \verb|resume*| option:
\begin{lstlisting}
\begin{enumerate}[resume*]
\item Watermelon
\item Orange
\end{enumerate}
\end{lstlisting}
we have (notice their alphabetical labels)
\begin{enumerate}[resume*]
\item Watermelon
\item Orange
\end{enumerate}
\section{Figures and Tables}
\subsection{Figures}
\paragraph{Figures and Including Images}
To import \textit{images}\index{Image} into the document, we need to load the \verb|graphics|\index{graphics@\texttt{graphics}} package and then use the \texttt{\textbackslash includegraphics\{<file\_\allowbreak name>\}}\index{includegraphics@\texttt{\textbackslash includegraphics}} command. The image should be placed under the project directory, and we hereby go through an example which is displayed as Figure \ref{fig:ada} on the next page. The code to produce that figure is
\begin{lstlisting}
\begin{figure}[ht!]
\centering
\includegraphics[width=0.4\linewidth]{graphics/Ada_Lovelace_portrait.jpg} % replace the path with your own file
\caption{The portrait of Ada Lovelace.}
\label{fig:ada}
\end{figure}
\end{lstlisting}
\begin{figure}[ht!]
\centering
\includegraphics[width=0.4\linewidth]{graphics/Ada_Lovelace_portrait.jpg}
\caption{The portrait of Ada Lovelace.}
\label{fig:ada}
\end{figure}
First, we need to enclose the \texttt{\textbackslash includegraphics} command within a \verb|figure|\index{figure@\texttt{figure}} environment. In fact, \verb|figure| is a type of \textit{floats}\index{Float} which can be freely moved around. The \verb|ht!| option indicates that priority is given to put the figure exactly in the place where the code is inserted (\verb|h|: here), or at the top of a page (\verb|t|). The \verb|width| option enforces the width of the image to some input value (and similarly, there are \verb|height| and \verb|scale|). The \texttt{\textbackslash caption}\index{caption@\texttt{\textbackslash caption}} command unsurprisingly generates the caption, while the \verb|label|\index{label@\texttt{\textbackslash label}} command works as it is in math mode and allows us to reference it by writing \texttt{\textbackslash ref\{fig:ada\}}\index{ref@\texttt{\textbackslash ref}}.
\paragraph{Subfigures}
We can create a set of smaller subfigures within a larger figure by utilizing the \verb|subcaption|\index{subcaption@\texttt{subcaption}} package and \verb|subfigure|\index{subfigure@\texttt{subfigure}} scopes. To illustrate, the following code is deployed to generate Figure \ref{fig:TC1}:
\begin{lstlisting}
\begin{figure}[ht!]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/MTS108082203.200812.jpg}
\caption{Typhoon Nuri (2008).}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/MTS212072303.201208.jpg}
\caption{Typhoon Vicente (2012).}
\end{subfigure}
\caption{The infrared satellite images of various Tropical Cyclones affecting Hong Kong.}
\label{fig:TC1}
\end{figure}
\end{lstlisting}
The \verb|b| option fixes the vertical alignment of \verb|subfigure| at the bottom.
\begin{figure}[ht!]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/MTS108082203.200812.jpg}
\caption{Typhoon Nuri (2008).}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/MTS212072303.201208.jpg}
\caption{Typhoon Vicente (2012).}
\end{subfigure}
\caption{The infrared satellite images of various Tropical Cyclones affecting Hong Kong. (Source: \href{https://agora.ex.nii.ac.jp/digital-typhoon/index.html.en}{Digital Typhoon})}
\label{fig:TC1}
\end{figure}
\paragraph{Continued Floats} To make an extended figure of subfigures that spans multiple pages, we can simply arrange them into separate \verb|figure| environments and call the \texttt{\textbackslash ContinuedFloat}\index{ContinuedFloat@\texttt{\textbackslash ContinuedFloat}} command in all the subsequent \verb|figure| groups. Continuing from the last example, we may have added
\begin{lstlisting}
\begin{figure}[hb!]
\ContinuedFloat % look here!
\caption{(Cont.) The infrared satellite images of various Tropical Cyclones affecting Hong Kong.}
\centering
\begin{subfigure}[b]{0.45\textwidth}
...
\caption{Typhoon Haima (2016).}
\end{subfigure}
...
\begin{subfigure}[b]{0.45\textwidth}
...
\caption{Typhoon Saola (2023).}
\end{subfigure}
\end{figure}
\end{lstlisting}
producing
\begin{figure}[hb!]
\ContinuedFloat
\caption{(Cont.) The infrared satellite images of various Tropical Cyclones affecting Hong Kong.}
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/HMW816080103.201604.jpg}
\caption{Typhoon Haima (2016).}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/HMW817082303.201713.jpg}
\caption{Typhoon Hato (2017).}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/HMW818091603.201822.jpg}
\caption{Typhoon Mangkhut (2018).}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{graphics/HMW923090103.202309.jpg}
\caption{Typhoon Saola (2023).}
\end{subfigure}
\end{figure}
\subsection{Tables}
\paragraph{Tabular Structures}
Just like embedding figures, building a \textit{table}\index{Table} requires us to place the content inside the corresponding \verb|table|\index{table@\texttt{table}} float environment. While it is possible to use the native \verb|tabular|\index{tabular@\texttt{tabular}} class for the actual table itself, a more powerful version is provided by the \verb|tabularx|\index{tabularx@\texttt{tabularx}} package and its class that bears the same name.\footnote{Sometimes, it can be more advantageous to use \texttt{tabular} than \texttt{tabularx}, but their syntax are similar.} This is demonstrated via Table \ref{tab:armyunits} thereafter, which is generated by
\begin{lstlisting}
\begin{table}[ht!]
\centering
\begin{tabularx}{\textwidth}{|l|p{0.55\textwidth}|>{\raggedleft}X|>{\raggedleft\arraybackslash}X|}
\hline
Unit & Description & Attack & Defense \\
\hline
Infantry & The most basic unit and backbone of any army, all-around abilities with a cheap cost. & 20 & 25 \\
\hline
Cavalry & The shock unit in an army with very strong power. & 40 & 30 \\
\hline
Artillery & The support unit that provides bombardment support from far away. & 30 & 5 \\
\hline
\end{tabularx}
\caption{The unit statistics table for a hypothetical game.}
\label{tab:armyunits}
\end{table}
\end{lstlisting}
\begin{table}[ht!]
\centering
\begin{tabularx}{\textwidth}{|l|p{0.55\textwidth}|>{\raggedleft}X|>{\raggedleft\arraybackslash}X|}
\hline
Unit & Description & Attack & Defense \\
\hline
Infantry & The most basic unit and backbone of any army, all-around abilities with a cheap cost. & 20 & 25 \\
\hline
Cavalry & The shock unit in an army with very strong power. & 40 & 30 \\
\hline
Artillery & The support unit that provides bombardment support from far away. & 30 & 5 \\
\hline
\end{tabularx}
\caption{The unit statistics table for a hypothetical game.}
\label{tab:armyunits}
\end{table}
The \verb|ht!| option, \verb|caption|, and \verb|label| work exactly like the figure counterparts. For the \verb|tabularx| environment, the first argument indicates the width of the entire table, set to \texttt{\textbackslash textwidth} here. The second argument \texttt{\{|l|p\{0.55\textbackslash textwidth\allowbreak\}|>\{\textbackslash raggedleft\}X|>\{\textbackslash raggedleft\textbackslash arraybackslash\}X|\}} indicates the justification of the columns: the first column is left-aligned (\verb|l|, similarly we have \verb|c| and \verb|r|) and its size will accommodate the text; the second column (\verb|p|) forces a width of $0.55$ times \texttt{\textbackslash textwidth}; the remaining width is distributed evenly to last two \verb|X| columns. The part of \texttt{>\{\textbackslash raggedleft\}} is applied to the \verb|X| columns, making them right-aligned.\footnote{\texttt{\textbackslash arraybackslash} is needed in the last column, see \href{https://tex.stackexchange.com/questions/372464/last-tabularx-column-raggedright-with-memoir}{\TeX{} StackExchange 372464}.} Finally, \texttt{|} and \texttt{\textbackslash hline} produce vertical/horiztonal separating lines; \texttt{\&} slices between the columns and \texttt{\textbackslash\textbackslash} marks the end of a row.
Also, note that \texttt{\textbackslash ContinuedFloat} can also be applied to \texttt{table} floats.
\paragraph{Caption by the Side} It is also possible to arrange the table so that the caption appears to the side of it. This is done by stacking the \verb|captionbeside|\index{captionbeside@\texttt{captionbeside}} environment provided by KOMA-script. For example, the code
\begin{lstlisting}
\begin{table}[ht!]
\begin{captionbeside}{This caption appears to the left of the Fibonacci numbers table.}[l][\textwidth]{
\adjustbox{valign=t}{
\begin{tabularx}{0.4\textwidth}{|X|X|}
\hline
$n$ & $F_n$ \\
\hline
$1$ & $1$ \\
\hline
$2$ & $1$ \\
\hline
$3$ & $2$ \\
\hline
$4$ & $3$ \\
\hline
$5$ & $5$ \\
\hline
$6$ & $8$ \\
\hline
\end{tabularx}}
}
\end{captionbeside}
\label{tab:fib}
\end{table}
\end{lstlisting}
produces Table \ref{tab:fib} below.
\begin{table}[ht!]
\begin{captionbeside}{This caption appears to the left of the Fibonacci numbers table.}[l][\textwidth]{\adjustbox{valign=t}{\begin{tabularx}{0.4\textwidth}{|X|X|}
\hline
$n$ & $F_n$ \\
\hline
$1$ & $1$ \\
\hline
$2$ & $1$ \\
\hline
$3$ & $2$ \\
\hline
$4$ & $3$ \\
\hline
$5$ & $5$ \\
\hline
$6$ & $8$ \\
\hline
\end{tabularx}}}
\end{captionbeside}
\label{tab:fib}
\end{table}
We supply the caption in the first argument, followed by two options: the relative position of the caption and the full width of the structure, finally with the actual \verb|tabularx| object. We also have to load the \verb|adjustbox|\index{adjustbox@\texttt{adjustbox}} package and use the corresponding command to make the table aligned at the top (\verb|valign=t|). This further requires us to first set the \texttt{\textbackslash KOMAoptions} to take \verb|captions=besidetop|\index{captions@\texttt{captions}} (likewise we have \verb|captions=besidebottom| and more).
\paragraph{Shared Numbering between Figures and Tables}
Sometimes we may want to share the numbering\index{Shared Numbering} between floats (including figures and tables). This is done by the following patch that can be inserted into the preamble:
\begin{lstlisting}
\makeatletter
\let\c@table\c@figure
\let\ftype@table\ftype@figure
\makeatother
\end{lstlisting}
This involves the primitive \TeX{} functions, so we will not discuss them there. For more information, read \href{https://stackoverflow.com/questions/3865036/using-a-single-count-for-figures-and-tables-in-latex}{StackOverflow 3865036}, and \href{https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do}{\TeX{} StackExchange 8351} for what the \texttt{\textbackslash makeatletter}\index{makeatletter@\texttt{\textbackslash makeatletter}} and \texttt{\textbackslash makeatother}\index{makeatother@\texttt{\textbackslash makeatother}} commands do.
\begin{exercisebox}
\begin{Exercise}
Try to import and load your favorite image into the document.
\end{Exercise}
\begin{Exercise}
Recreate any one of the tables in Chapter \ref{chap:maths}.
\end{Exercise}
\end{exercisebox}
\section{Minipages and Multiple Columns}
\paragraph{Minipages}
Sometimes we may want to split the content into smaller blocks that are embedded within the current page, and can be placed or ordered (e.g.\ parallel) in the way we want. The \verb|minipage|\index{minipage@\texttt{minipage}} environment basically acts like a more versatile version of a \verb|parbox| command and serves this purpose. For example, something like
\begin{lstlisting}
\begin{center}
\begin{minipage}[b]{0.48\textwidth}
\lipsum[6]
\end{minipage}
\hfill
\begin{minipage}[b]{0.48\textwidth}
\lipsum[7]
\end{minipage}
\end{center}
\end{lstlisting}
yields \par
\begin{center}
\begin{minipage}[b]{0.48\textwidth}
\lipsum[6]
\end{minipage}
\hfill
\begin{minipage}[b]{0.48\textwidth}
\lipsum[7]
\end{minipage}
\end{center}
The \verb|b| option indicates that the two blocks will be bottom-aligned, provided that their width is fixed to $0.48$ times \texttt{\textbackslash textwidth} and thus they fit in the main text area.
\paragraph{Parallel Columns} The \verb|parcolumns|\index{parcolumns@\texttt{parcolumns}} package can also achieve an effect similar to \verb|minipage| and is more specialized for typesetting different pieces in two or more parallel columns. It also supports page breaks. Using the same example, we can write
\begin{lstlisting}
\begin{parcolumns}{2}
\colchunk[1]{\lipsum[6]}
\colchunk[2]{\lipsum[7]}
\colplacechunks
\colchunk[1]{\lipsum[8]}
\colchunk[2]{\lipsum[9]}
\end{parcolumns}
\end{lstlisting}
to get\\
\begin{parcolumns}{2}
\colchunk[1]{\lipsum[6]}
\colchunk[2]{\lipsum[7]}
\colplacechunks
\colchunk[1]{\lipsum[8]}
\colchunk[2]{\lipsum[9]}
\end{parcolumns}
where the first argument of \texttt{parcolumns} clearly indicates the number of columns and the \texttt{\textbackslash colplacechunks}\index{colplacechunks@\texttt{\textbackslash colplacechunks}} command releases the loaded \texttt{\textbackslash colchunk[<col\allowbreak\_index>]}\index{colchunk@\texttt{\textbackslash colchunk}} and goes to the next paragraph.
\paragraph{Multiple Columns} A task closely related to what \verb|parcolumns| does above is to typeset a single, continuous stream of text along multiple columns, like in many academic papers. The \texttt{multicol} package is designed for this and will carry out the automatic splitting. For example, by encapsulating the text inside the \verb|multicols|\index{multicols@\texttt{multicols}} environment as
\begin{lstlisting}
\begin{multicols}{2}
Zhuge Liang (born 181, Yangdu [now Yinan, Shandong province], China--died August 234, Wuzhangyuan [now in Shaanxi province], China) was a celebrated adviser to Liu Bei, founder of the Shu-Han dynasty (221--263/264).
...
A mechanical and mathematical genius, Zhuge is credited with inventing a bow for shooting several arrows at once and with perfecting the Eight Dispositions, a series of military tactics. In the Sanguozhi yanyi (Romance of the Three Kingdoms), the great 14th-century historical novel, Zhuge is one of the main characters; he is portrayed as being able to control the wind and foretell the future.
\end{multicols}
\end{lstlisting}
(again with the number of columns indicated in the first argument) we may acquire the following layout:
\begin{multicols}{2}
Zhuge Liang (born 181, Yangdu [now Yinan, Shandong province], China--died August 234, Wuzhangyuan [now in Shaanxi province], China) was a celebrated adviser to Liu Bei, founder of the Shu-Han dynasty (221--263/264).
Quick Facts: \\
Wade-Giles romanization: Chu-ko Liang \\
Courtesy name: Kongming \\
Born: 181, Yangdu [now Yinan, Shandong province], China \\
Died: August 234, Wuzhangyuan [now in Shaanxi province], China (aged 53)
Zhuge, to whom supernatural powers often are ascribed, has been a favoured character of many Chinese plays and stories. Legend states that Liu Bei, then a minor military figure, heard of Zhuge Liang’s great wisdom and came three times to the wilderness retreat to which Zhuge had retired to seek him out as an adviser. It is known that Zhuge helped Liu organize a large army and found a dynasty. Liu was so impressed with Zhuge’s wisdom that on his deathbed Liu urged his son to depend on Zhuge’s advice and urged Zhuge to ascend the throne himself if the prince were unable to rule. Some historical accounts indicate that Zhuge died from illness while leading a military campaign in 234.
A mechanical and mathematical genius, Zhuge is credited with inventing a bow for shooting several arrows at once and with perfecting the Eight Dispositions, a series of military tactics. In the Sanguozhi yanyi (Romance of the Three Kingdoms), the great 14th-century historical novel, Zhuge is one of the main characters; he is portrayed as being able to control the wind and foretell the future. (Source: Encyclopaedia Britannica)
\end{multicols}
\paragraph{Two Columns Set-up} We can also pass the \verb|twocolumn=true|\index{twocolumn@\texttt{twocolumn}} option to \texttt{\textbackslash KOMAoptions} to demand the entire book to be formatted in two columns globally. However, note that it will greatly mess up the layout of this book. (The decision to adopt such a format should be made at an early time!)
\paragraph{In the Same Page}
Last but not least, text will normally be distributed across pages, and if we want to force a specific part to stay together on the same page, we can surround it within the \texttt{samepage}\index{samepage@\texttt{samepage}} scope.