LaTeX Cheat Sheet
Basic LaTeX reference
LaTeX is a powerful typesetting system widely used for creating professional documents with complex formatting, like math formulae, especially in academic domains. Here’s a cheat sheet for LaTeX typesetting.
Basic TeX/LaTeX commands
Basic LaTeX Document Structure
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Your content here
\end{document}
Text Formatting
- Bold: \textbf{text}
- Italic: \textit{text}
- Underline: \underline{text}
Math Mode
Inline math: $$x^2 + y^2 = z^2$$ Display math: $$ E = mc^2 $$
Greek Letters
- Alpha: $$\alpha$$
- Beta: $$\beta$$
- Gamma: $$\gamma$$
- Delta: $$\delta$$
Operators and Symbols
- Sum: $$\sum_{i=1}^n x_i$$
- Integral: $$\int_a^b f(x) dx$$
- Fraction: $$\frac{numerator}{denominator}$$
- Square root: $$\sqrt{x}$$
Subscripts and Superscripts
- Subscript: $$x_i$$
- Superscript: $$x^2$$
- Combined: $$x_i^2$$
Matrices
\begin{matrix}
a & b \\
c & d
\end{matrix}
Equations
\begin{equation}
f(x) = ax^2 + bx + c
\end{equation}
Lists
Unordered list:
\begin{itemize}
\item First item
\item Second item
\end{itemize}
Ordered list:
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
Tables
See the details in a separate section below.
\begin{tabular}{|c|c|}
\hline
Header 1 & Header 2 \\
\hline
Cell 1 & Cell 2 \\
\hline
\end{tabular}
Sections
\section{Main Section}
\subsection{Subsection}
\subsubsection{Sub-subsection}
Remember to include necessary packages and use appropriate document class for your specific needs.
Adding diagrams
To include diagrams in a LaTeX cheat sheet, you have several options:
-
Use the graphicx package to insert images:
- Add \usepackage{graphicx} to your preamble
- Use \includegraphics[options]{filename} to insert images (please see for the details below.)
-
Create Venn diagrams using the venndiagram package:
- Add \usepackage{venndiagram} to your preamble
- Use \begin{venndiagram3sets} environment for three-set diagrams
-
Plot graphs using the tikz package:
- Add \usepackage{tikz} to your preamble
- Use \begin{tikzpicture} environment to create plots and graphs
-
Create tables to organize information:
- Use \begin{tabular} environment for simple tables
- For more complex tables, consider packages like longtable or tabu
-
Use subfigures for multiple related diagrams:
- Add \usepackage{subcaption} to your preamble
- Use \begin{subfigure} environment within a figure environment
Remember to adjust the positioning and sizing of your diagrams to fit the cheat sheet format. You may need to experiment with options like [width=0.8\textwidth] or [scale=0.5] to ensure your diagrams fit well within the cheat sheet layout.
Adding images
To add images using the graphicx package in LaTeX, follow these steps:
- Include the graphicx package in your document preamble:
\usepackage{graphicx}
- Place your image files in the same directory as your LaTeX file or use the \graphicspath command to specify the image directory:
\graphicspath{{images/}}
- Use the \includegraphics command within your document to insert the image:
\includegraphics[options]{filename}
- For better organization and formatting, wrap the image in a figure environment:
\begin{figure}[placement]
\centering
\includegraphics[options]{filename}
\caption{Your caption here}
\label{fig:label}
\end{figure}
- Adjust the image size using options like width, height, or scale:
\includegraphics[width=0.5\textwidth]{filename}
- Reference the image in your text using the \ref command with the label you assigned.
Remember to compile your document to see the inserted images.
Adding Tables to LaTeX document
Adding tables to a LaTeX document is a common task that can be accomplished using the tabular environment.
Here’s how to create tables in LaTeX with several examples:
Basic Table Structure
The basic structure of a table in LaTeX uses the tabular environment:
\begin{tabular}{column_specifiers}
content
\end{tabular}
Column specifiers define the alignment and borders of each column:
- l: left-aligned
- c: center-aligned
- r: right-aligned
- |: vertical line between columns
Simple Table Example
Here’s a basic 3x3 table:
\begin{tabular}{lcr}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
Table with Borders
To add borders, use vertical (|) and horizontal (\hline) lines:
\begin{tabular}{|l|c|r|}
\hline
Left & Center & Right \\
\hline
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}
Table Environment
For better formatting and captions, use the table environment:
\begin{table}[h!]
\centering
\caption{Sample Table}
\label{tab:sample}
\begin{tabular}{|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
A & B & C \\
D & E & F \\
\hline
\end{tabular}
\end{table}
Multi-column and Multi-row Tables
For more complex tables, you can use \multicolumn and \multirow commands:
\usepackage{multirow}
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{2}{|c|}{Merged Columns} & Column 3 \\
\hline
\multirow{2}{*}{Merged Rows} & B1 & C1 \\
& B2 & C2 \\
\hline
\end{tabular}
Table with Custom Column Types
For more advanced formatting, you can define custom column types:
\usepackage{array}
\begin{tabular}{|l|>{\centering\arraybackslash}p{3cm}|r|}
\hline
Left & Centered Paragraph & Right \\
\hline
A & This text is centered and wraps within a 3cm wide column & 1 \\
\hline
\end{tabular}
Remember to include necessary packages like array, multirow, or booktabs for advanced table features.
Adding Table of Contents
Adding a table of contents to a LaTeX document is a simple process. Here’s how to do it:
- Basic Table of Contents
To create a basic table of contents, use the \tableofcontents command:
\documentclass{article}
\begin{document}
\tableofcontents
\section{Introduction}
\section{Main Content}
\section{Conclusion}
\end{document}
This will automatically generate a table of contents based on your document’s sections.
- Customizing the Table of Contents
You can customize the depth of the table of contents using the \setcounter command:
\setcounter{tocdepth}{2}
\tableofcontents
This will show sections and subsections in the table of contents.
- Changing the Title
To change the default “Contents” title, use:
\renewcommand*\contentsname{Tutorials}
\tableofcontents
This will change the title to “Tutorials”.
- Adding Unnumbered Sections
To add unnumbered sections to the table of contents, use:
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
This will include the unnumbered section in the table of contents.
- Including Lists of Figures and Tables
You can also add lists of figures and tables:
\tableofcontents
\listoffigures
\listoftables
Remember to compile your document twice to ensure the table of contents is properly generated.
Example
Here’s a complete example demonstrating these features:
\documentclass{article}
\usepackage{blindtext}
\title{Sample Document}
\author{John Doe}
\date{}
\begin{document}
\maketitle
\renewcommand*\contentsname{Document Contents}
\setcounter{tocdepth}{2}
\tableofcontents
\section{Introduction}
\blindtext
\section{Main Content}
\subsection{Subsection 1}
\blindtext
\subsection{Subsection 2}
\blindtext
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
\blindtext
\section{Conclusion}
\blindtext
\end{document}
This example includes a custom title for the table of contents, sets the depth to include subsections, and adds an unnumbered section to the table of contents.