Source file basics part 6
Below is the source file (.tex) demonstrating the basics of LaTeX.
- List environments
- Page breaks
- Marginal notes
- Footnotes
- Tables
- hrefs
\documentclass{sample}
\usepackage{booktabs}
\usepackage{hyperref}
% for non-floating table captions:
\usepackage{caption}
\begin{document}
\section{List environments}
Lists are defined by their own environments (with \textbackslash begin) as bulleted lists with \textbackslash itemize, as numbered lists with \textbackslash enumerate and as captions with \textbackslash description. Each entry is denoted by \textbackslash item.
\emph{Always declare the first item \textbackslash item right after the beginning of the environment}
Bulleted:
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
Numbered:
\begin{enumerate}
\item Item 1
\item Item 2
\item Item 3
\item[] Item 4 without a number
\item[a] Item 5 with the letter identity (this is absolute referencing)
\item[a] Item 6 with the same letter identity (this is absolute referencing)
\end{enumerate}
Captioned (the third element is caption is duplicated):
\begin{description}
\item[Caption 1] Item 1
\item[Caption 2] Item 2
\item[Caption 2] Item 3
\end{description}
As implied, captioned lists are absolute referencing.
\section{New pages and page breaks}
Some lists can span multiple pages. To introduce a page break, use \textbackslash newpage. This preserves the current content width. To stretch new page content to the normal width use \textbackslash pagebreak.
\newpage
\section{Nested lists}
It is possible to nest up to four list environments (with \textbackslash begin and \textbackslash end). It is not necessary to indent nested environments, although this may assist the author.
\begin{itemize}
\item Item 1
\begin{itemize}
\item Subitem 1
\item Subitem 2
\item Subitem 3
\end{itemize}
\item Item 2
\item Item 3
\end{itemize}
\begin{enumerate}
\item Item 1
\begin{itemize}
\item Subitem 1
\item Subitem 2
\item Subitem 3
\end{itemize}
\item Item 2
\item Item 3
\end{enumerate}
\section{Marginal comments}
Authors introduce marginal comments with \textbackslash marginpar. The side chosen depends on the current page number and document typsetting.
\marginpar{Some comment}
Try not to use these comments too often, their placement may not be consistent. Do not use marginal comments in math environments.
\section{Footnotes}
LaTeX can reference footnotes automatically. Here is one now.\footnote{This is all about footnotes}
\newpage
\section{href, LaTeX tables and booktabs}
In general, the default tables generated by LaTeX look awful. A better alternative is something like booktabs see \href{https://ctan.org/pkg/booktabs}{the official docs}.
It all starts with \textbackslash tabular, followed by some cell alignment (l for left, c for centre and r for right).
The header row starts with a thick line denoted by \textbackslash toprule, the content given by \textbackslash midrule before finishing the table with \textbackslash bottomrule. As with matrices, columns are delimited with \& and rows delimited with \textbackslash\textbackslash.
\begin{table}
\begin{center}
\begin{tabular}{llr}
\toprule
Column 1 & Column 2 & Price (\$) \\
\midrule
Something & Something else & 13.65 \\
Alpha & Beta & 92.50 \\
One & Two & 33.33 \\
\bottomrule
\end{tabular}
\caption{Floating table generated by bookstab}
\label{Ta:floatingtable}
\end{center}
\end{table}
The table is considered \textit{floating}, allowing LaTeX to decide where to place the table. This need not be based on the table definition in the source. To force the table in a given position, omit the \textbackslash begin\{table\} command.
So, to force the table to show below, as shown below, use a \textit{non-floating table}. This also affects how to add table captions, using the package \texttt{caption} and command \textbackslash captionof:
\begin{center}
\begin{tabular}{llr}
\toprule
Column 1 & Column 2 & Price (\$) \\
\midrule
Something & Something else & 13.65 \\
Alpha & Beta & 92.50 \\
One & Two & 33.33 \\
\bottomrule
\end{tabular}
\captionof{table}{Non-floating table generated by bookstab}
\label{Ta:nonfloatingtable}
\end{center}
So to summarise, Table \ref{Ta:floatingtable} is a floating table, and Table \ref{Ta:nonfloatingtable} is non-floating table.
\end{document}
The source file and (required) document class file are included. A generated PDF can be found here.