Getting Started with LaTeX - jonathancolmer/lab-guide GitHub Wiki

LaTeX is a typesetting tool commonly used to neatly handle equations, tables, and figures. Most papers are written in LaTeX using Overleaf, an online editor that allows for easy collaboration.


1. Setting Up LaTeX

There are two ways to get started with LaTeX: using a browser-based editor called Overleaf, or installing LaTeX locally. We recommend familiarizing yourself with both options.

1.1 Using LaTeX via Overleaf

Overleaf is particularly useful when projects require collaboration between multiple parties.

UVA provides free Overleaf professional accounts for students and faculty. Follow the steps below to access Overleaf through UVA:

  1. Follow this link (https://www.overleaf.com/edu/virginia) and click ‘Sign Up’
  2. Follow account setup instructions (name, password, institution, etc.). Click ‘Skip’ if asked about Premium.

1.2 Installing LaTeX locally

Local installations of LaTeX are useful when you are the sole collaborator on a project. LaTeX requires both a compiler and an editor to be used properly. In most cases it is best to use VSCode (with the LaTeX extension, see VSCode guide) as the front-end editor for best functionality.

  1. For Windows
    1. Follow this link (https://miktex.org/download) and download and install Basic MiKTeX.
    2. Open and run the Installer.
  2. For Mac
    1. Download and Install TeXShop, linked here. Relevant information for getting it setup is under the “Obtaining” and “Installing” tabs.

2. Navigating LaTeX

Below is a list of LaTeX’s most basic features to help you get started. LaTeX has many more capabilities, and we’ve included resources to consult for further details. ChatGPT can also be helpful for exploring LaTeX.

2.1 File Structure

Every LaTeX file must begin with a document class and \begin{document}. In addition, LaTeX handles section numbering and referencing.

\documentclass{article}

\begin{document}

*Your content goes here.*

`\section{Introduction}` 

\end{document}

2.2 Math in LaTeX

LaTeX handles math operations in special environments that must be made clear to the compiler. There are three main ways to denote math equations:

  1. Inline: Used for math equations within a line, and enclosed within \( … \) or $ … $
  2. Display Math: Appears in its own line and centred, enclosed within \[ … \]
  3. Numbered: Used to number equations, and must be within the equation environment

\begin{equation}

*equation*

\end{equation}

2.3 Using Packages for Advanced Functionality

LaTeX allows users to use additional packages to use more advanced features. Common practice is to include all packages at the top of a .tex file to make for more streamlined code, with the \usepackage{package_name} function. Here’s a (non-comprehensive) list of LaTeX Packages you may come across:

  • pdflscape: Allows specific pages in the document to be set in landscape orientation
  • amsmath, amsfonts, amssymb: enhanced math typesetting, additional math fonts and symbols
  • natbib: Supports customized citation styles, especially useful for author-year citations.
  • graphicx: Essential for including and manipulating images in the document.
  • rotating: Enables rotation of objects, such as tables or figures
  • booktabs: Improves table formatting with professional-looking horizontal lines.
  • caption: Customizes the appearance of figure and table captions
  • threeparttable: Enhances tables by dividing them into three parts: notes, captions, and the main body
  • url: Properly formats URLs in the document
  • comment: Allows commenting out large sections of the document

2.4 Navigating Tables

For most tables it is ok (and more convenient) to rely on ChatGPT for formatting. Knowing the basics will save you time for simpler tables and allow you to correct/tweak anything GPT may give you. Here we’ve provided a short overview for you to get started.

\begin{table}[h]

\centering

\begin{threeparttable}

`\caption{Descriptive Statistics}`

`\label{tab:desc_stats}`

`\begin{tabular}{lcc}`

  `\toprule`

  `Variable & Mean & Std. Dev. \\`

  `\midrule`

  `Income & 54,321 & 12,345 \\`

  `Age    & 38.5   & 10.2 \\`

  `\bottomrule`

`\end{tabular}`

`\begin{tablenotes}`

  `\footnotesize`

  `\item Note: Sample includes 500 respondents. All values in USD.`

`\end{tablenotes}`

\end{threeparttable}

\end{table}

The template above relies on the use of packages ‘threeparttable’ and ‘booktabs’. Some general formatting tips:

  • Align numerics right (r) and labels left (l) or center (c) as appropriate.
  • Use \footnotesize to keep footnotes compact

2.5 Handling Images and Figures:

Similar to tables, you will often have to include figures and images in your LaTeX files. The following should give you a good sense for how to navigate that, and covers most of what you would need. Anything beyond what is listed here can be looked up in the LaTeX documentation.

\begin{figure}[h]

`\centering`

`\includegraphics[width=0.8\textwidth]{“file path to image/fig”}`

`\caption{Example of a plotted result}`

`\label{fig:example}`

\end{figure}

There are few key options that you may have to use, particularly as it comes to figure placement.

  • width=0.8\textwidth:scales the image to 80% of text width.
  • [h], [t], [b], [H]: suggests placement here/top/bottom/precisely here.
  • \label{fig:example}: enables cross-referencing.

2.6 Further Resources:

  1. Overleaf Documentation can be helpful to get started
  2. A Harvard Crash Course on starting with LaTeX
  3. Penn’s list of LaTeX resources.