Skip to content

Instantly share code, notes, and snippets.

@stephenleo
Last active July 2, 2022 16:23
Show Gist options
  • Save stephenleo/1c808797436aefa075f42e025c02f556 to your computer and use it in GitHub Desktop.
Save stephenleo/1c808797436aefa075f42e025c02f556 to your computer and use it in GitHub Desktop.
LaTeX

Useful LaTeX Tips

1. Inserting Tables

Generate LaTeX table code by importing your table in this Online LaTeX Generator

2. Wrap text in Tables

To wrap text inside tables, update your the column inside your \begin{tabular}{} tag.
Eg: If you want the first column to take a maximum 30% of the line width and wrap the remaining text, change the first l to p{0.3\linewidth}

% from
\begin{tabular}{@{}lll@{}}

% to
\begin{tabular}{@{}p{0.3\linewidth}ll@{}}

3. Inserting figures or tables that span the whole page (in multi-column document)

Add * to the end of the tag. eg:

\begin{figure*}
\end{figure*}

\begin{table*}
\end{table*}

4. Organizing content in multiple files

You can insert one LaTeX document inside another by using the \input{} tag.
Eg: If your project is organized as follows

project_dir/
|-- 00_main.tex
|-- 01_intro.tex
|-- 02_body.tex
|-- 03_conclusion.tex

Then you can include the contents from all the files inside 00_main.tex by including the following lines in it.

\input{01_intro}
\input{02_body}
\input{03_conclusion}

5. Referencing Sections

You can reference any section in the text by adding a \label{} to that section and using the \ref{} tag to that label. Eg:

% use label reference in text
Section \ref{Introduction} introduces the problem statement

% create label for the section
\section{Introduction}
\label{Introduction}
% Inserting an Image file to LaTeX document
% width=0.45\textwidth for 2-column document
% width=0.95\textwidth for 1-column document
\begin{figure}[ht!]
\centering
\includegraphics[width=0.45\textwidth, keepaspectratio]{path_to_image.png}
\label{fig:fig_label}
\caption{Figure Caption}
\end{figure}
% Inserting Multiple Subfigures
\begin{figure}[ht!]
\centering
\begin{subfigure}{\textwidth}
\includegraphics[width=0.45\textwidth, keepaspectratio]{path_to_image_1.png}
\end{subfigure}
\begin{subfigure}{\textwidth}
\includegraphics[width=0.45\textwidth, keepaspectratio]{path_to_image_2.png}
\end{subfigure}
\label{fig:fig_label}
\caption{Figure Caption}
\end{figure}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment