Debian Codegraph @

texmf-dist/doc/latex/ualberta/02_Chapters/04_Figures_Tables.tex

raw
1 \chapter{Figures, Tables, \& Plates}\label{ch:figureandtables}
2 \section{Introduction}
3 Figures and Tables play a crucial role in conveying information effectively in academic documents.
4 This chapter will delve into the intricacies of incorporating figures and tables in your \LaTeX\ document, exploring various features and advanced techniques to enhance the visual appeal and clarity of your content.
5 While there are many types of figures that one might have in their document, this Chapter more specifically focuses on the inclusion of graphic figures (pictures), as well as how to lay out multi figures (sub-figures).
6
7 \warning{Throughout this Chapter there will be code listings that include lines that show the required packages. These lines should be included in your \LaTeX\ preamble, not in the body of your document. To make this easy I have actually included a document specifically to add your packages too. This can be found in the includePackages.tex file found in the 00\_LaTeX\_Files folder.}
8
9 \tip{\path{./00_LaTeX_Files/includePackages.tex} includes all the packages required for creating all the examples in this document, some of these will not be necessary for your own thesis, however, I have included comments on all packages for what they are used for. This allows you to make a decision on if you will need them as well.
10 If you are unsure, you may just comment out the line so as to not forget the packages that were originally included.}
11
12 \section{Inserting Figures}
13 In \LaTeX, figures are included using the \pkg{graphicx} package.
14 The \cmd{includegraphics} command is used to insert an image.
15 Let's consider an example:
16
17 \begin{lstlisting}[float=ht,caption=A Basic Example of Including a Figure.,label=lst:figureExample,style=LaTeXStyle,basicstyle=\small\ttfamily,]
18 \usepackage{graphicx}
19
20 \begin{figure}[htb]
21 \centering
22 \includegraphics[width=0.7\linewidth]{example-image}
23 \caption{Example Figure}
24 \label{fig:example}
25 \end{figure}
26 \end{lstlisting}
27
28 \begin{figure}[H]
29 \centering
30 \includegraphics[width=0.7\linewidth]{example-image}
31 \caption{This is an example of a single figure similar to that produced by \Cref{lst:figureExample}.}
32 \label{fig:singleImage}
33 \end{figure}
34
35 In this example, the \env{figure} environment is used to contain the image.
36 The \cmd{centering} command ensures the image is centred horizontally.
37 The \opt{width} parameter is used to control the size of the image; in this case, it has been set to \opt{0.45\cmd{linewidth}} which will make it fill a space that is 0.45 tiems the width of the current line.
38 The \cmd{caption} and \cmd{label} commands provide a caption and label for referencing, respectively.
39
40 Figures can be formatted to meet specific requirements.
41 The \cmd{subfigure} command from the \pkg{subcaption} package can be used for side-by-side figures:
42
43 \begin{lstlisting}[float=ht,caption=,label=lst:subfigureExample,style=LaTeXStyle,basicstyle=\small\ttfamily,]
44 \usepackage{subcaption}
45
46 \begin{figure}[htb]
47 \begin{subfigure}{0.45\linewidth}
48 \centering
49 \includegraphics[width=\linewidth]{example-image-a}
50 \caption{Subfigure A} % Leave blank for just letter
51 \label{subfig:a}
52 \end{subfigure}
53 \hfill
54 \begin{subfigure}{0.45\linewidth}
55 \centering
56 \includegraphics[width=\linewidth]{example-image-b}
57 \caption{Subfigure B} % Leave blank for just letter
58 \label{subfig:b}
59 \end{subfigure}
60 \caption{Example with Subfigures}
61 \label{fig:subfigures}
62 \end{figure}
63 \end{lstlisting}
64
65 This example uses the \env{subfigure} environment to create subfigures within a larger figure (as show in \Cref{fig:doubleImage}.
66 The \cmd{hfill} command adds horizontal space between the subfigures.
67
68 \begin{figure}[H]
69 \centering
70 \begin{subfigure}{0.45\linewidth}
71 \includegraphics[width=\linewidth]{example-image}
72 \caption{} % Leave blank for just letter
73 \label{fig:doubleImage:a}
74 \end{subfigure}
75 ~
76 \begin{subfigure}{0.45\linewidth}
77 \includegraphics[width=\linewidth]{example-image}
78 \caption{} % Leave blank for just letter
79 \label{fig:doubleImage:b}
80 \end{subfigure}
81 \caption{This is an example of a double image figure similar to that produced by \Cref{lst:subfigureExample}.}
82 \label{fig:doubleImage}
83 \end{figure}
84
85 While this section provided a few examples on how to make some figures and subfigures, I would strongly recommend checking out some of the more complex examples of figures shown in \Cref{app:examplefigures}.
86 This will provide the code and examples for how to create more intricate subfigures and layouts.
87
88 \section{Tables and Tabularx}
89 Tables in \LaTeX\ are created using the \env{tabular} environment.
90 The \pkg{tabularx} package is particularly useful when you want the table to automatically adjust its width.
91 Let's define some custom column types for convenience:
92
93 \begin{lstlisting}[float=ht,caption=,label=lst:newcolumntyps,style=LaTeXStyle,basicstyle=\small\ttfamily,]
94 \usepackage{tabularx}
95 \newcolumntype{C}{>{\centering\arraybackslash}X}
96 \newcolumntype{L}{>{\raggedright\arraybackslash}X}
97 \newcolumntype{R}{>{\raggedleft\arraybackslash}X}
98 \end{lstlisting}
99 Now, let's create a table using tabularx:
100 \begin{lstlisting}[float=ht,caption=,label=lst:tabularx,style=LaTeXStyle,basicstyle=\small\ttfamily,]
101 \begin{table}[htb]
102 \centering
103 \begin{tabularx}{\linewidth}{|C|L|R|}
104 \hline
105 \textbf{Centered} & \textbf{Left Justified} & \textbf{Right Justified} \\
106 \hline
107 Content & More content & Additional content \\
108 \hline
109 \end{tabularx}
110 \caption{Example Table with Tabularx}
111 \label{tab:example}
112 \end{table}
113 \end{lstlisting}
114
115 In this example, the \env{tabularx} environment is used, and the custom column types \opt{C}, \opt{L}, and \opt{R} are applied to the columns.
116 This ensures the content is centered, left-justified, and right-justified, respectively.
117
118 \section{Advanced Table Features}
119
120 To create professional-looking tables, the \pkg{booktabs} package can be employed.
121 It provides commands for better spacing and styling of tables:
122
123 \begin{lstlisting}[float=ht,caption=,label=lst:booktabs,style=LaTeXStyle,basicstyle=\small\ttfamily,]
124 \usepackage{booktabs}
125
126 \begin{table}[htb]
127 \centering
128 \begin{tabular}{ccc}
129 \toprule
130 \textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} \\
131 \midrule
132 Content 1 & Content 2 & Content 3 \\
133 Content 4 & Content 5 & Content 6 \\
134 \bottomrule
135 \end{tabular}
136 \caption{Example Table with Booktabs}
137 \label{tab:booktabs_example}
138 \end{table}
139 \end{lstlisting}
140
141 The \cmd{toprule}, \cmd{midrule}, and \cmd{bottomrule} commands create horizontal rules with appropriate spacing.
142
143 \section{Additional Packages for Enhanced Table Functionality}
144
145 Several other packages can be employed to enhance table functionality:
146
147 The \pkg{longtable} package allows tables to span multiple pages, which is useful for large datasets.
148 The \pkg{multirow} and \pkg{multicolumn} packages provide commands for cells that span multiple rows or columns, respectively.
149 The \pkg{makecell} package enables more complex table layouts.
150 Each of these packages comes with its set of commands and options. Let's briefly explore the usage of \pkg{longtable}, \pkg{multirow}, and \pkg{multicolumn}:
151
152 \begin{lstlisting}[float=ht,caption=,label=lst:additionaltablepackages,style=LaTeXStyle,basicstyle=\small\ttfamily,]
153 \usepackage{longtable}
154 \usepackage{multirow}
155 \usepackage{multicolumn}
156
157 % Example Longtable
158 \begin{longtable}{|c|c|}
159 \caption{Longtable Example} \label{tab:longtable} \\
160 \hline
161 \textbf{Header 1} & \textbf{Header 2} \\
162 \hline
163 \endfirsthead
164 \hline
165 \textbf{Header 1} & \textbf{Header 2} \\
166 \hline
167 \endhead
168 Content 1 & Content 2 \\
169 Content 3 & Content 4 \\
170 \hline
171 \end{longtable}
172
173 % Example Multirow and Multicolumn
174 \begin{table}[htb]
175 \centering
176 \begin{tabular}{|c|c|c|}
177 \hline
178 \multirow{2}{*}{\textbf{Multirow-Col1}} & \multicolumn{2}{c|}{\textbf{Multicolumn-Col2-3}} \\
179 \cline{2-3}
180 & \textbf{Column 2} & \textbf{Column 3} \\
181 \hline
182 Content 1 & Content 2 & Content 3 \\
183 \hline
184 \end{tabular}
185 \caption{Example Table with Multirow and Multicolumn}
186 \label{tab:multirow_multicolumn}
187 \end{table}
188 \end{lstlisting}
189
190 In these examples, the \env{longtable} environment is used for tables that span multiple pages.
191 The \cmd{multirow} command is employed to create cells that span multiple rows, while \cmd{multicolumn} is used for cells that span multiple columns.
192
193 \section{Conclusion}
194 This Chapter provided a comprehensive overview of including figures and tables in your \LaTeX\ document.
195 From basic insertion of figures to advanced table formatting using packages like \pkg{tabularx}, \pkg{booktabs}, and others, you now have a solid foundation to include tables and figures in your thesis.
196 While this provides a lot of details on how to add figures that have already been pre-generated, one might want to generate figures on the spot potentially even using data generated from other programs (such as MatLab\textsuperscript{\tiny\textregistered}, Python, \textit{etc}.).
197 For this \Cref{ch:plotsandgraphs} provides in-depth workings of the \pkg{pgfplots} package and how to generate consistent and professional looking plots and graphs.