rss logo

Practical LaTeX Notes & Examples for Document Formatting

Latex Logo

Introduction

I often use LaTeX to make my own reports. I will use this page as a personal reminder, hope it will help other people.

Windows

I personaly use MiKTeX, a program that can be run with or without installation. The official website for downloading the software: https://miktex.org/.

GNU/Linux

Under GNU/Linux, you'll need to install the texlive packages.

  • Install software packages:
root@host:~# apt update && apt install texlive texlive-latex-extra
  • Or complete installation:
root@host:~# apt update && apt install texlive-full
  • Convert to pdf:
user@host:~$ pdflatex file.tex
  • Convert a tex file to rtf format (to import a document into Word or Writer):
root@host:~# apt update && apt install latex2rtf user@host:~$ latex2rtf file.tex

Front Page

  • Code:
\documentclass{article} \usepackage[utf8]{inputenc} \author{shebangthedolphins.net} \title{My Title} \begin{document} \maketitle \end{document}
  • Overview:
Example of a LaTeX front page with title, author, and date displayed in a minimalistic layout
  • Add table of contents:
\begin{document} \maketitle \newpage \tableofcontents \newpage \end{document}

Bullets

  • Code:
\begin{document} \begin{itemize} \item[$\bullet$] \textbf{Name :} shebangthedolphins.net \item[$\bullet$] \textbf{Version :} 1.0 \subitem $\bullet$ element 1 \subitem $\bullet$ element 2 \end{itemize} \end{document}
  • Overview:
Example of a nested bullet list in LaTeX showing a main list with subitems for name and version details

Tables

Multipage tables

  • Code:
\documentclass{article} \usepackage{longtable} \begin{document} \begin{center} \begin{longtable}{ | p{3.6cm} |p{3.6cm} | p{3.6cm} | } \hline \textbf{Programs} & \textbf{Editors} & {\textbf{Version}} \\ \hline \hline Microsoft Visual C++ 2005 Redistributable & Microsoft Corporation & 8.0.56336 \\ \hline Microsoft Visual C++ 2005 Redistributable (x64) & Microsoft Corporation & 8.0.56336 \\ \hline Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.17 & Microsoft Corporation & 9.0.30729 \\ \hline Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161 & Microsoft Corporation & 9.0.30729.6161 \\ \hline Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17 & Microsoft Corporation & 9.0.30729 \\ \hline Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.6161 & Microsoft Corporation & 9.0.30729.6161 \\ \hline Microsoft Visual C++ 2010 x64 Redistributable - 10.0.40219 & Microsoft Corporation & 10.0.40219 \\ \hline Microsoft Visual C++ 2010 x86 Redistributable - 10.0.40219 & Microsoft Corporation & 10.0.40219 \\ \hline Microsoft Visual C++ 2010 x86 Runtime - 10.0.40219 & Microsoft Corporation & 10.0.40219 \\ \hline Microsoft Visual C++ 2012 x64 Additional Runtime - 11.0.61030 & Microsoft Corporation & 11.0.61030 \\ \hline Microsoft Visual C++ 2012 x64 Minimum Runtime - 11.0.61030 & Microsoft Corporation & 11.0.61030 \\ \hline Microsoft Visual C++ 2012 x86 Additional Runtime - 11.0.61030 & Microsoft Corporation & 11.0.61030 \\ \hline Microsoft Visual C++ 2012 x86 Minimum Runtime - 11.0.61030 & Microsoft Corporation & 11.0.61030 \\ \hline Microsoft Visual C++ 2013 x64 Additional Runtime - 12.0.21005 & Microsoft Corporation & 12.0.21005 \\ \hline Microsoft Visual C++ 2013 x64 Minimum Runtime - 12.0.21005 & Microsoft Corporation & 12.0.21005 \\ \hline Microsoft Visual C++ 2013 x86 Additional Runtime - 12.0.21005 & Microsoft Corporation & 12.0.21005 \\ \hline Microsoft Visual C++ 2013 x86 Minimum Runtime - 12.0.21005 & Microsoft Corporation & 12.0.21005 \\ \hline Microsoft Visual C++ 2015 x64 Additional Runtime - 14.0.24212 & Microsoft Corporation & 14.0.24212 \\ \hline Microsoft Visual C++ 2015 x64 Minimum Runtime - 14.0.24212 & Microsoft Corporation & 14.0.24212 \\ \hline Microsoft Visual C++ 2015 x86 Additional Runtime - 14.0.24212 & Microsoft Corporation & 14.0.24212 \\ \hline Microsoft Visual C++ 2015 x86 Minimum Runtime - 14.0.24212 & Microsoft Corporation & 14.0.24212 \\ \hline Microsoft Visual Studio 2010 Shell (Isolated) - ENU & Microsoft Corporation & 10.0.40219 \\ \hline Microsoft VSS Writer for SQL Server 2014 & Microsoft Corporation & 12.2.5000.0 \\ \hline \end{longtable} \end{center} \end{document}
  • Overview:
Example of a LaTeX table showcasing a formatted multipage layout with columns for programs, editors, and versions

Tables with Multicolumns

  • Code:
\documentclass{article} \usepackage{longtable} \usepackage{array} \begin{document} \begin{center} %Ref : https://tex.stackexchange.com/questions/338478/break-long-word-in-tabular \newcolumntype{P}[1]{>{\hspace{0pt}}p{#1}} \begin{longtable}{ |P{5cm}|P{2cm}|P{2cm}|P{2cm}| } \hline \textbf{Function} & \textbf{mplayer} & \textbf{mpv} & \textbf{vlc}\\ \hline \hline \multicolumn{4}{|c|}{Commands} \\ \hline Adjust audio delay (A/V sync) & -/+ & Ctrl-/Ctrl+ & j/k \\ \hline Adjust subtitle delay & x/z & Z/z & h/g \\ \hline \end{longtable} \end{center} \end{document}
  • Overview:
Example of a LaTeX table with multicolumn formatting, showing commands for adjusting audio and subtitle delay in media players mplayer, mpv, and vlc

Tables with Multicolumns II

  • Code:
\documentclass{article} \usepackage{longtable} %pour les longs tableaux de plusieurs pages \usepackage{multirow} \usepackage[table,dvipsnames]{xcolor} %pour colorer les cellules (table) et colorier le texte (erreur si les deux sont séparés avec un usepackage chacun ex : \usepackage[table]{xcolor} + \usepackage[dvipsnames]{xcolor} \begin{document} \section{AV Test} \setlength\LTleft{-2.0cm} %réduire la mage à gauche de 2cm \begin{center} \begin{longtable}{ | p{3.5cm} | p{5.5cm} | c | c | c | } \hline & & \textbf{Test AV} & \textbf{Test Virus} & \textbf{Quarantine} \\ \hline \hline \multirow{2}{*}{\textbf{Update}} & Success & \textcolor{Green}{OK} & - & \cellcolor{black} \\ \cline{2-5} & Fails & - & \textcolor{Red}{KO} & \cellcolor{black} \\ \hline \multirow{4}{*}{\textbf{Scan AV}} & AV Scan & \textcolor{Green}{OK} & \textcolor{Green}{OK} & \cellcolor{black} \\ \cline{2-5} & Boot Scan & \textcolor{Green}{OK} & \textcolor{Green}{OK} & \cellcolor{black} \\ \cline{2-5} & Manual Scan & \textcolor{Green}{OK} & \textcolor{Green}{OK} & \cellcolor{black} \\ \hline \multirow{3}{*}{\textbf{Check Virus}} & Real Time Protection & \textcolor{Green}{OK} & \textcolor{Green}{OK} & \textcolor{Green}{OK} \\ \cline{2-5} & CD/DVD & - & - & - \\ \cline{2-5} & USB & \textcolor{Green}{OK} & \textcolor{Green}{OK} & \textcolor{Green}{OK} \\ \hline \multirow{3}{3.5cm}{\textbf{Test with compressed achives}} & Real Time Protectoin & \textcolor{Green}{OK} & \textcolor{Green}{OK} & \textcolor{Red}{KO}\\ \cline{2-5} & CD/DVD & - & \textcolor{Green}{OK} & - \\ \cline{2-5} & Clé USB & \textcolor{Green}{OK} & \textcolor{Green}{OK} & \textcolor{Red}{KO} \\ \hline \textbf{Stop and Start} & Try to stop then restart computer & \textcolor{Red}{KO} & \cellcolor{black} & \cellcolor{black}\\ \hline \end{longtable} \end{center} \setlength\LTleft{0cm} %réinit marge à gauche \end{document}
  • Overview:
Example of a LaTeX table with color-coded cells, showing results of an antivirus test with columns for test AV, test virus, and quarantine

Images

Images with caption

  • Code:
\documentclass{article} \usepackage{graphicx} % Required for including images \graphicspath{{C:/Users/std/Documents/LaTeX_Images/}} %root path to images \usepackage[font=small,labelfont=bf]{caption} % Required for specifying captions to tables and figures \begin{document} \begin{center} \includegraphics[width=120mm]{std/banniere.jpg} %std is a folder inside C:/Users/std/Documents/LaTeX_Images/ \captionof{figure}{shebangthedolphins.net - banner} \end{center} \end{document}
  • Overview:
Banner example in LaTeX featuring an image of a dolphin with custom annotation and caption 'shebangthedolphins.net - banner'

Images at the right of the text

  • Code:
\documentclass{article} \usepackage{wrapfig} %Right text images \usepackage{graphicx} % Required for including images \graphicspath{{C:/Users/std/Documents/LaTeX_Images/}} %root path to images \usepackage[font=small,labelfont=bf]{caption} % Required for specifying captions to tables and figures \begin{document} \begin{wrapfigure}{r}{0.45\textwidth} %this figure will be at the right \centering \includegraphics[width=0.20\textwidth]{EricCartman.png} \captionof{figure}{Eric Cartman} \includegraphics[width=0.25\textwidth]{ButtersStotch.png} \captionof{figure}{Butter Stotch} \end{wrapfigure} \section{South Park} \subsection{Introduction (Wikipedia)} \textbf{South Park} is an American animated sitcom created by Trey Parker and Matt Stone and developed by Brian Graden for Comedy Central. The series revolves around four boys—Stan Marsh, Kyle Broflovski, Eric Cartman, and Kenny McCormick—and their exploits in and around the titular Colorado town. The show became infamous for its profanity and dark, surreal humor that satirizes a wide range of topics towards a mature audience. Parker and Stone developed the show from The Spirit of Christmas, two consecutive animated shorts. The latter became one of the first Internet viral videos, ultimately leading to South Park's production. The pilot episode was produced using cutout animation, leading to all subsequent episodes being produced with computer animation that emulated the cutout technique. South Park features a very large ensemble cast of recurring characters. Since its debut on August 13, 1997, 308 episodes of South Park have been broadcast. It debuted with great success, consistently earning the highest ratings of any basic cable program. Subsequent ratings have varied but it remains one of Comedy Central's highest-rated shows and is slated to air new episodes through 2022. Since 2000, each episode has typically been written and produced in the week preceding its broadcast, with Parker serving as the primary writer and director. A one-hour special episode, titled "The Pandemic Special", premiered on September 30, 2020. South Park has received numerous accolades, including five Primetime Emmy Awards, a Peabody Award, and numerous inclusions in various publications' lists of greatest television shows. The show's popularity resulted in a feature-length theatrical film, South Park: Bigger, Longer \& Uncut which was released in June 1999, less than two years after the show's premiere, and became a commercial and critical success, and garnered a nomination for an Academy Award. In 2013, TV Guide ranked South Park the tenth Greatest TV Cartoon of All Time. \end{document}
  • Overview:
Example of a LaTeX document with a South Park introduction, including embedded images of Eric Cartman and Butter Stotch alongside descriptive text

Lines of code

PowerShell

  • Code:

Download this file: latex-listings-powershell.tex and put it in the same folder as your .tex document.

\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[dvipsnames]{xcolor} \usepackage{listings} %needed for code parts % -- POWERSHELL \definecolor{lst-gray}{rgb}{0.98,0.98,0.98} \definecolor{lst-blue}{RGB}{40,0.0,255} \definecolor{lst-green}{RGB}{65,128,95} \definecolor{lst-red}{RGB}{200,0,85} \input{./latex-listings-powershell.tex} \lstdefinestyle{PowerShell} { commentstyle=\color{lst-green}, basicstyle=\small\ttfamily, backgroundcolor=\color{lst-gray}, breaklines=true, captionpos=b, columns=fixed, extendedchars=true, frame=single, framesep=2pt, keepspaces=true, keywordstyle=\color{lst-blue}, language={PowerShell}, numbers=left, numberstyle=\small\ttfamily, showstringspaces=false, stringstyle=\color{lst-red}, tabsize=2, } \lstnewenvironment{PowerShell} {\lstset{style=PowerShell}} {} % -- FIN POWERSHELL \begin{document} \begin{lstlisting}[style=PowerShell] $users = New-Object System.Collections.ArrayList [void] $users.AddRange( ("Bruce Wayne","Alfred Pennyworth","Selina KYLE")) $password = "ComplexP@ss908!" $addomain = "shebangthedolphins.net" \end{lstlisting} \end{document}
  • Overview:
Example of syntax-highlighted PowerShell code in LaTeX displaying the creation of an array list with user information and domain settings

DOS

  • Code:
\documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{listings} %needed for code parts % DOS (https://tex.stackexchange.com/questions/63961/how-to-accept-three-different-languages-on-lstlisting/63962#63962 et https://tex.stackexchange.com/questions/193470/how-to-show-similar-display-of-codes-of-different-programming-languages-in-latex) \lstdefinestyle{Common} { basicstyle=\scriptsize\ttfamily\null, numbers=left, numbersep=1em, frame=single, framesep=\fboxsep, framerule=\fboxrule, xleftmargin=\dimexpr\fboxsep+\fboxrule, xrightmargin=\dimexpr\fboxsep+\fboxrule, breaklines=true, breakindent=0pt, tabsize=5, columns=flexible, showstringspaces=false, captionpos=b,% or t for top (default) abovecaptionskip=0.5\smallskipamount, % there is also belowcaptionskip } \lstdefinestyle{DOS} { style=Common, backgroundcolor=\color{Black}, basicstyle=\color{White}\scriptsize\ttfamily, numbers=none, } \lstnewenvironment{DOS} {\lstset{style=dos}} {} % -- FIN DOS \begin{document} \begin{lstlisting}[style=dos] C:\Users\Administrator>fsutil file createnew test.txt 1048576000 \end{lstlisting} \end{document}
  • Overview:
Example of a DOS command in LaTeX creating a test file using fsutil with a specified size

raw code

  • Code:
\documentclass{article} \begin{document} \section{AutoIt Backup Script} \begingroup \fontsize{7pt}{9pt}\selectfont \begin{verbatim} #include <Date.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> [...] $SFolders[2] = "Personal" $SFolders[3] = "My Music" $SFolders[4] = "My Pictures" $SFolders[5] = "My Video" \end{verbatim} \endgroup \end{document}
  • Overview:
Example of a LaTeX document displaying an AutoIt backup script with comments, code, and instructions for automating backups

raw code with border

  • Code:
\documentclass{article} \usepackage{fancyvrb} \begin{document} \section{Cisco Configuration} \begingroup \fontsize{7pt}{9pt}\selectfont \begin{Verbatim}[frame=single] switch(config)#line console 0 switch(config-line)#exec-timeout 15 \end{Verbatim} \endgroup \end{document}
  • Overview:
Example of a LaTeX document displaying a Cisco configuration snippet with commands for console line and timeout settings

Miscellaneous

Symbols

  • Copyright:
\begin{document} \section{Fairphone} \textbf{{Fairphone }\copyright} is a social enterprise company which aims to develop smartphones that are designed and produced with minimal environmental impact. \end{document}
  • Overview:
Example of a LaTeX document showcasing the use of a copyright symbol in a text about the Fairphone social enterprise

http reference

  • Code:
\documentclass{article} \usepackage{url} \begin{document} \section{shebangthedolphins.net} Welcome to the \textbf{\#!the dolphins} webstite\footnote{\url{https://shebangthedolphins.net}}, this is all about \textbf{rock 'n' roll music/(noise)} and \textbf{tux}! I'm just an \textbf{alien} so there will be some \textbf{English mistakes}. Don't hesitate to contact me (my email : \textbf{admin} + \textbf{@} + \textbf{shebangthedolphins.net}), in order to correct them or just to say hi! :) We can write url like this : \url{https://shebangthedolphins.net} \end{document}
  • Overview:
Example of a LaTeX document displaying a URL with a footnote and text introducing the shebangthedolphins.net website

Landscape

  • Code:
\documentclass{article} \usepackage{lscape} %landscape module \usepackage[font=small,labelfont=bf]{caption} % Required for specifying captions to tables and figures \usepackage{graphicx} % Required for including images \begin{document} \begin{landscape} \section{RDS MFA} \begin{center} \centerline{\includegraphics[width=175mm]{rds_mfa.png}} \captionof{figure}{RDS MFA} \end{center} \end{landscape} \end{document}
  • Overview:
Example of a LaTeX document displaying a landscape-oriented diagram for RDS MFA configuration with labeled components and flow arrows

Header

Header text centered in a red box. Top Secret style.

  • Code:
\documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{fancyhdr} %header \pagestyle{fancy} \renewcommand\fbox{\fcolorbox{red}{white}} %red border %\fancyhf{} % clear all header and footer fields \renewcommand{\headrulewidth}{0pt} %remove header black bar \chead{\fbox{\textcolor{Red}{\textbf{TOP SECRET}}}} \rhead{} %clear auto right header
  • Overview:
Example of a LaTeX document featuring a 'TOP SECRET' styled header in red with an introduction to South Park characters and context
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address