Skip to content

Instantly share code, notes, and snippets.

@vhbui02
Last active December 25, 2023 18:12
Show Gist options
  • Save vhbui02/1c8e9eb97546a7515ec7a6f80f82965c to your computer and use it in GitHub Desktop.
Save vhbui02/1c8e9eb97546a7515ec7a6f80f82965c to your computer and use it in GitHub Desktop.
[Overleaf learning] Wanna try to write report/thesis/article using different tool

Why use Latex?

  • Complex mathmatics, tables and technical contents
  • Footnotes, cross-ref, biblio
  • Indexes, Glossaries, ToC, List of Figures, List of Tables,...
  • Highly customizable, intrinsic programmability
  • Thousands of free add-ons
  • LaTeX file create template which author can use to write many papers
  • Thousand of templates: articles, reports, books, CVs, ...

Cheat sheet

The content - Body of the document

Between \begin{document} and \end{document}

Preamble

  • Overleaf only grab main.tex file in a project
  • Before \begin{document} is called preamble
  • Define language, loading packages,

Controls overall appearance of document

\documentclass[12pt, a4paper]{article | report | book | ...}

  • Parameters are defined in square bracket
  • 12pt = font size (alter: 9pt, 11pt, 13pt, ... Def = 10pt)
  • a4paper = paper size (alter: letterpaper, legalpaper)

Title, Author and Date

  • Defined in Prem. \title{My first LaTeX document} \author{VH\thanks{Teached by Overleaf}} \date{December 2023} or \today
  • Typeset the 3, use \maketitle in Body.

Bold, italics, underlining

  • \textbf{...}
  • \textit{...}, alter = \emph{...}, use with italic will turn it back to normal
  • \underline{...}

Adding images

3 ways:

  • Insert Figure button.
  • Copy and paste image.
  • Use Code Editor write code insert image.
% Prem
\usepackage{graphicx}
\graphicspath{{images/}} % Configure the dir that graphicx will search for images
% Body
\includegraphics{universe} % load an img called universe.jpg in images dir

Best practices:

  • Omit the file extension: \includegraphics{universe} not \includegraphics{universe.jpg}
  • Not whitespace of multiple dots in filename, extension part must be lowercase.

Images can be Captioned, Labeled and Ref

% Prem
\usepackage{graphicx}
\graphicspath{{images/}}
% Body
\begin{figure}[h] % positioning of figures
   	\centering % use to center anything after it
    \includegraphics[width=0.75\textwidth]{mesh} % text width is stored in \textwidth command
    \caption{A nice plot.} % can be placed above or below
    \label{fig:mesh1} %  
\end{figure}

\ref{fig:mesh1} % the name of figure
\pageref{fig:mesh1} % the number of the page that contains the figure

Creating lists

Environments: encap the latex code req to implement a specific typeset feature.

% Body
\begin{figure | tabular | ...}
\end{...}

Unordered lists

% Body
\begin{itemize}[label=$\circ$]
	\item[] The item has no bullet point
  \item This item has default bullet point
  \item[-] This item's bullet point has changed
\end{itemize}
% Body
% Numbering style can be changed
\begin{enumerate}
	\item First entry
  \item The list numbers increases with each entry added

Adding math to LaTeX

2 ways:

  • inline: formula that's part of paragraph. 3 syntax:
  • \( ... \)
  • $ ... $
  • \begin{math} ... \end{math}
  • display: formula that is seperate line. 3 syntax:
  • \[ ... \]
  • \begin{displaymath} ... \end{displaymath}
  • \begin{equation} ... \end{equation}
% Body

% Inline
Equation $E=mc^2$, discovered in 1905 by Albert Einstein. 

% Display
The mass-energy equivalence is described by the famous equation
\[E=mc^2\]
discovered in 1905 by Albert Einstein.

Basic document structure

Abstracts

Brief overview/summary of their core topics, arguments. Using abstract environment

% Body
\begin{abstract}
...
\end{abstract}

Paragraphs and new lines

3 syntex:

  • Enter twice (or blank line between 2 paragraph)
  • \\ command
  • \newline command

Note: LaTeX auto indents paragraph, except right after headings

\usepackage{parskip} manipulate paragraph

Chapters and Sections

  • book class = **chapters + sections + subsections + ...```
  • letter class, is diff
% Prem
\documentclass{book}

% Body
\chapter{First Chapter}
\section{Introduction}
\subsection{...}
\subsubsection{...}

% less encounter
\part{...} 
\paragrapth{...}
\subparagraph{...}

Tables

\begin{center} % align center to whole table within text width of the page
\begin{tabular}{|c||c|c|} % c = align center to column, | = vertical rules, 2 rules is also okey
\hline % horizontal rules
\hline % two rules is also okay
 cell1 & cell2 & cell3 \\ % & = delimiter for each columns
\hline
 cell4 & cell5 & cell6 \\ % end a table row use the newline \\
\hline
 cell7 & cell8 & cell9    
\end{tabular}
\end{center}

Table captioned, labeled and ref

\begin{table}[h!] % or H
\centering % alter to \begin{center} ... \end{center}
\begin{tabular}{||c c c c||}
...
\end{tabular}

\caption{Table to test captions and labels}
\label{table:data}
\end{table}

Table \ref{table:data} shows how to add a table caption and ref a table on \pageref{table:data}

Adding a ToC

\tableofcontents

Unnumbered section don't get included in ToC by default: \addcontentsline{toc}{section}{Unnumbered Section} \addcontentsline{toc}{subsection}{Unnumbered Subsection}

Loading packages

\usepackage{somepackage}: load package using default settings \usepackage[options]{somepackage}: load package using modified settings \usepackage[total={6.5in,8.75in},top=1.2in, left=0.9in, includefoot]{geometry}

Some interesting things I've founded on Internet

Paper size, orientation, margins

% Method 1
\usepackage[legalpaper, landscape, margin=2in]{geometry}

% Method 2
\usepackage{geometry}
\geometry{legalpaper, landscape, margin=2in}

% Change margin
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

Fine tuning latex page dimension

\usepackage{layout}: visualize the documents current layout \layout vs \layout*, the latter recal internal vals used to draw the graphic

\vspace{10pt} add vertical space setlength{\<parameter>}{?pt}

\layout*

Add dummy taxt

\blindtext[10]
\usepackage{blindtext}

Table positioning

  • [h]: place the float at approx location in the LaTeX code
  • [H]: place the float at precisely location in the LaTeX code
  • [t]: top page
  • [b]: bottom page
  • [p]: special page for float only
  • [<htbpH>!]: override for determining "good" float positions.

Note: use H or h!, need these lines:

\usepackage{float}
\restylefloat{table}

List of figures and tables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment