📄 LaTeX Document Preparation

Personal reference for professional document creation

Getting Started with LaTeX

What is LaTeX?

LaTeX is a document preparation system that produces high-quality typeset documents, especially for academic and technical writing.

Advantages:

  • Professional typography
  • Excellent mathematical notation
  • Automatic cross-referencing
  • Consistent formatting
  • Version control friendly

Installation Options

Local Installation:

  • TeX Live (Cross-platform)
  • MiKTeX (Windows)
  • MacTeX (macOS)

Online Editors:

  • Overleaf (Collaborative)
  • ShareLaTeX (Now part of Overleaf)
  • Papeeria

Essential Editors

Desktop Editors:

  • TeXworks (Simple, cross-platform)
  • TeXmaker (Feature-rich)
  • VS Code with LaTeX Workshop
  • Vim/Emacs with LaTeX plugins

Features to Look For:

  • Syntax highlighting
  • Auto-completion
  • Built-in PDF viewer
  • Error highlighting

Document Types

Common Classes:

  • article - Journal articles, short papers
  • report - Longer documents with chapters
  • book - Books and theses
  • beamer - Presentations
  • letter - Formal letters

Basic Document Structure

Minimal Document

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\title{My First LaTeX Document}
\author{Donghao Song}
\date{\today}

\begin{document}
\maketitle

\section{Introduction}
This is my first LaTeX document.

\section{Main Content}
Here is the main content of my document.

\end{document}
                        

Document Class Options

% Font sizes
\documentclass[12pt]{article}

% Paper size
\documentclass[a4paper]{article}

% Two-column layout
\documentclass[twocolumn]{article}

% Multiple options
\documentclass[12pt,a4paper,twocolumn]{article}
                        

Essential Packages

% Character encoding
\usepackage[utf8]{inputenc}

% Language support
\usepackage[english]{babel}

% Enhanced math
\usepackage{amsmath, amssymb, amsthm}

% Graphics
\usepackage{graphicx}

% Hyperlinks
\usepackage{hyperref}

% Better tables
\usepackage{booktabs}

% Margins
\usepackage{geometry}
                        

Sectioning Commands

\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}

% Numbered sections
\section{Introduction}
\section{Methodology}

% Unnumbered sections
\section*{Acknowledgments}

% Table of contents
\tableofcontents
                        

Text Formatting

Font Styles

\textbf{Bold text}
\textit{Italic text}
\underline{Underlined text}
\texttt{Typewriter text}
\emph{Emphasized text}

% Font sizes
\tiny{tiny text}
\small{small text}
\large{large text}
\Large{Large text}
\huge{huge text}
                        

Lists

% Unordered list
\begin{itemize}
    \item First item
    \item Second item
    \item Third item
\end{itemize}

% Ordered list
\begin{enumerate}
    \item First item
    \item Second item
    \item Third item
\end{enumerate}

% Description list
\begin{description}
    \item[Term 1] Definition 1
    \item[Term 2] Definition 2
\end{description}
                        

Alignment

% Center alignment
\begin{center}
    This text is centered.
\end{center}

% Left alignment
\begin{flushleft}
    This text is left-aligned.
\end{flushleft}

% Right alignment
\begin{flushright}
    This text is right-aligned.
\end{flushright}
                        

Spacing

% Line breaks
Text before\\
Text after

% Paragraph breaks
First paragraph.

Second paragraph.

% Vertical spacing
\vspace{1cm}
\vspace{0.5in}

% Horizontal spacing
Word\hspace{1cm}Word
                        

Mathematical Notation

Inline and Display Math

% Inline math
The equation $E = mc^2$ is famous.

% Display math
\[
    E = mc^2
\]

% Numbered equations
\begin{equation}
    F = ma
\end{equation}

% Aligned equations
\begin{align}
    x &= y + z \\
    a &= b + c
\end{align}
                        

Common Math Symbols

% Greek letters
\alpha, \beta, \gamma, \Delta, \Omega

% Operators
\sum, \prod, \int, \oint

% Relations
\leq, \geq, \neq, \approx, \equiv

% Special symbols
\infty, \partial, \nabla, \pm, \mp

% Fractions
\frac{a}{b}, \frac{x^2 + y^2}{z}

% Superscripts and subscripts
x^2, x_i, x_{ij}
                        

Matrices

% Basic matrix
\begin{matrix}
    a & b \\
    c & d
\end{matrix}

% Matrix with parentheses
\begin{pmatrix}
    1 & 2 \\
    3 & 4
\end{pmatrix}

% Matrix with brackets
\begin{bmatrix}
    1 & 2 \\
    3 & 4
\end{bmatrix}

% Determinant
\begin{vmatrix}
    a & b \\
    c & d
\end{vmatrix}
                        

Theorem Environments

% In preamble
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}

% In document
\begin{theorem}
    This is a theorem.
\end{theorem}

\begin{proof}
    This is the proof.
\end{proof}
                        

Figures and Tables

Including Graphics

% In preamble
\usepackage{graphicx}

% Basic figure
\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{filename.pdf}
    \caption{This is a figure caption.}
    \label{fig:label}
\end{figure}

% Reference the figure
As shown in Figure~\ref{fig:label}...
                        

Creating Tables

% Basic table
\begin{table}[h]
    \centering
    \begin{tabular}{|l|c|r|}
        \hline
        Left & Center & Right \\
        \hline
        1 & 2 & 3 \\
        4 & 5 & 6 \\
        \hline
    \end{tabular}
    \caption{This is a table caption.}
    \label{tab:label}
\end{table}

% Professional table with booktabs
\begin{table}[h]
    \centering
    \begin{tabular}{lcc}
        \toprule
        Item & Value 1 & Value 2 \\
        \midrule
        A & 1.23 & 4.56 \\
        B & 2.34 & 5.67 \\
        \bottomrule
    \end{tabular}
    \caption{Professional table.}
\end{table}
                        

Float Placement

% Placement options
\begin{figure}[h]   % here
\begin{figure}[t]   % top
\begin{figure}[b]   % bottom
\begin{figure}[p]   % separate page
\begin{figure}[H]   % force here (needs float package)

% Multiple options
\begin{figure}[htbp]  % try here, top, bottom, page

% Force placement
\usepackage{float}
\begin{figure}[H]
    % Content
\end{figure}
                        

Subfigures

% In preamble
\usepackage{subcaption}

% Subfigures
\begin{figure}[h]
    \centering
    \begin{subfigure}{0.45\textwidth}
        \includegraphics[width=\textwidth]{fig1.pdf}
        \caption{First subfigure}
        \label{fig:sub1}
    \end{subfigure}
    \hfill
    \begin{subfigure}{0.45\textwidth}
        \includegraphics[width=\textwidth]{fig2.pdf}
        \caption{Second subfigure}
        \label{fig:sub2}
    \end{subfigure}
    \caption{Main caption}
    \label{fig:main}
\end{figure}
                        

References and Citations

BibTeX Setup

% In preamble
\usepackage{natbib}  % or biblatex

% At end of document
\bibliography{references}  % references.bib file
\bibliographystyle{plain}  % or other styles

% Compilation order
% 1. latex document.tex
% 2. bibtex document
% 3. latex document.tex
% 4. latex document.tex
                        

BibTeX Entry Examples

% In references.bib file
@article{smith2023,
    author = {John Smith},
    title = {An Important Paper},
    journal = {Journal of Important Things},
    year = {2023},
    volume = {15},
    pages = {123-145},
    doi = {10.1234/example}
}

@book{doe2022,
    author = {Jane Doe},
    title = {A Great Book},
    publisher = {Academic Press},
    year = {2022},
    address = {New York}
}
                        

Citations in Text

% With natbib
\cite{smith2023}           % (Smith, 2023)
\citep{smith2023}          % (Smith, 2023)
\citet{smith2023}          % Smith (2023)
\citeyear{smith2023}       % 2023
\citeauthor{smith2023}     % Smith

% Multiple citations
\cite{smith2023,doe2022}

% With page numbers
\citep[p.~15]{smith2023}
\citep[see][p.~15]{smith2023}
                        

Cross-References

% Labels
\section{Introduction}\label{sec:intro}
\begin{equation}\label{eq:einstein}
    E = mc^2
\end{equation}
\begin{figure}...\label{fig:results}
\begin{table}...\label{tab:data}

% References
See Section~\ref{sec:intro}.
Equation~\ref{eq:einstein} shows...
Figure~\ref{fig:results} illustrates...
Table~\ref{tab:data} contains...

% Page references
See page~\pageref{sec:intro}.
                        

Common Issues and Solutions

Compilation Errors

  • Missing $: Math mode not properly closed
  • Undefined control sequence: Typo in command or missing package
  • File not found: Check file paths and extensions
  • Too many }'s: Mismatched braces

Formatting Issues

  • Overfull hbox: Text extends beyond margin
  • Underfull hbox: Too much white space
  • Figure placement: Use placement options [htbp]
  • Page breaks: Use \newpage or \clearpage

Best Practices

  • Use semantic markup (e.g., \emph{} instead of \textit{})
  • Keep source files organized
  • Use version control
  • Compile frequently to catch errors early
  • Use consistent indentation