Latex Intro Slides II
Latex Intro Slides II
• Calling packages.
• Defining new commands.
• How to include figures (easy) and tables (less easy).
• How to use and track references.
We’ve talked a lot about the body of a LATEX document, but very
little about the preamble.
The preamble allows you to call packages, set up your document,
and define new commands. A nice preamble for this session is as
follows:
\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
Mathematical Typesetting:
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
Drawing Figures:
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pstricks}
Page formatting:
\usepackage{color}
\usepackage{subfig}
\usepackage[footnotesize,hang]{caption}
\usepackage{showkeys}
When you have some spare time, teach yourself to draw pictures
with the tikz package. This is a useful skill to have.
The Preamble
\newcommand{\grad}{\boldsymbol{\nabla}}
\newcommand{\diff}[2]{\frac{\mathrm{d} #1}{\mathrm{d} #2}}
\newcommand{\pdiff}[2]{\frac{\partial #1}{\partial #2}}
\renewcommand{\vec}[1]{\boldsymbol{#1}}
∂ ∂ ∂
∇=i +j +k .
∂x ∂y ∂z
d(u · v ) du dv
= ·v +u· .
dt dt dt
Pictures
\begin{center}
\includegraphics[width=0.25\textwidth]{dice.png}
\end{center}
You can use most image formats, but .png and .pdf work best.
Pictures
\begin{figure}[hb]
\includegraphics[height=5cm]{dice.png}
\caption{This is a picture of dice.}
\label{dicepic}
\end{figure}
The [hb] argument tells the document to place the figure at the
current point (“here”) or at the bottom of a page. You can also
use t for the top of a page, and p to give the figure a page to itself.
LATEX often has a mind of its own when it comes to placing figures.
Pictures
\begin{center}
\begin{tabular}{|l||c|r}\hline
A & B & C \\ \hline \hline
Monday & Tuesday & Wednesday \\
$\alpha$ & $\beta$ & $\gamma + 7 = 12$ \\ \hline
\end{tabular}
\end{center}
The argument of tabular tells the table what vertical lines to use,
and what alignment to use in each column (left, centre, right).
A B C
Monday Tuesday Wednesday
α β γ + 7 = 12
The argument of tabular tells the table what vertical lines to use,
and what alignment to use in each column (left, centre, right).
When you write a report, you often have to include citations. This
could be a long (and very dull) lecture on its own.
Your BibTeX file is plaintext, and can be edited in the same editor
you use for your .tex files.
Articles:
Required: author, title, journal, year, pages.
Optional: volume, number, publisher, language.
Books:
Required: author (or editor), title, publisher, year.
Optional: edition, volume, number, series, address, language.
Citations
@article{lustri2018nanoptera,
title={Nanoptera in a period-2 {T}oda chain},
author={Lustri, C. J. and Porter, M. A.},
journal={SIAM Journal on Applied Dynamical Systems},
volume={17},
number={2},
pages={1182--1212},
year={2018}
}
The first argument is the label that you’ll use to cite the article.
Try to be descriptive and consistent.
Citations
@book{boas2006mathematical,
author={Boas, Mary L.},
publisher={John Wiley & Sons},
title={Mathematical methods in the physical sciences},
year={2006}
}
To get your citation to show up, type the following at the end of
your document:
\bibliographystyle{plain}
\bibliography{citationlist.bib}
The citation list won’t contain every single article, book, or other
document listed in the BibTeX file. It will only include documents
that are mentioned in the text:
\bibliographystyle{plain}
\bibliography{citationlist.bib}
To get this to work, compile the LaTeX, to tell the compiler which
citations to look for. Then compile to BibTeX, which puts the
bibliography in place. Then compile the LaTeX again to get the
cross-referencing right. Then compile once more for luck.
Citations
LATEX is extremely versatile, and I’m still learning new things all the
time. Get used to looking for solutions online, because the answer
to any question you might ask is out there somewhere.