LaTeX is one of the most powerful tools for creating professional documents, especially in academic, scientific, and technical fields. Beginners often struggle because LaTeX uses code instead of a graphical editor—but once you understand the main commands and where they are used, it becomes a highly efficient system. This article provides practical LaTeX code examples and explains exactly when and why to use each one.
1. Basic Document Structure
Every LaTeX document starts with a declaration of the document class and required packages. This is the core “skeleton” of your file.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\begin{document}
\section{Introduction}
\lipsum[1]
\end{document}
Where to use it:
Use this basic structure for articles, reports, papers, essays, and simple documents. It’s the foundation for almost every LaTeX project.
2. Using Document Classes for Specific Projects
LaTeX has different classes depending on what type of document you want to create.
Article
For papers, homework, essays, and standard documents.
\documentclass{article}
Report
For multi-chapter documents, theses, and dissertations.
\documentclass{report}
Book
For full-length books with front matter and chapters.
\documentclass{book}
Beamer
For presentations (similar to PowerPoint but with LaTeX quality).
\documentclass{beamer}
Where to use them:
Choose the class depending on the type of project—each class formats chapters, sections, headers, and page layout differently.
3. Adding Packages (Extensions)
Packages extend the power of LaTeX. Some of the most important:
\usepackage{graphicx} % for images
\usepackage{amsmath} % for advanced math
\usepackage{booktabs} % for professional tables
\usepackage{hyperref} % for clickable links
Where to use them:
Whenever you need extra functionality. For example, use graphicx to insert images or amsmath for equations.
4. Inserting Images
One of the most common tasks.
\usepackage{graphicx}
\begin{figure}[h]
\centering
\includegraphics[width=0.6\textwidth]{example-image}
\caption{Sample Image}
\end{figure}
Where to use it:
Scientific papers, presentations, thesis documents, reports—anywhere you need figures.
5. Creating Tables
LaTeX is known for producing beautiful tables, especially with booktabs.
\begin{table}[h]
\centering
\begin{tabular}{lcr}
\toprule
Left & Center & Right \\
\midrule
A & B & C \\
D & E & F \\
\bottomrule
\end{tabular}
\caption{Simple Table Example}
\end{table}
Where to use it:
Use this in scientific papers, data summaries, reports, and presentations where table quality matters.
6. Writing Mathematical Equations
LaTeX is the standard for mathematical writing.
Inline math:
Einstein's equation $E = mc^2$ is well known.
Displayed equation:
\[
a^2 + b^2 = c^2
\]
Advanced equation:
\begin{equation}
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
\end{equation}
Where to use it:
Mathematics, physics, engineering, economics, statistics—any discipline involving formulas.
7. Lists (Itemized and Numbered)
Lists are fundamental for structuring content.
Bullet list
\begin{itemize}
\item First item
\item Second item
\end{itemize}
Numbered list
\begin{enumerate}
\item Step one
\item Step two
\end{enumerate}
Where to use it:
Use lists in lecture notes, instructions, articles, and reports to structure ideas clearly.
8. TikZ Graphics (Diagrams and Drawings)
TikZ is a powerful tool to create custom diagrams.
\usepackage{tikz}
\begin{tikzpicture}
\draw (0,0) -- (2,2);
\node at (1,1) {Hello, TikZ};
\end{tikzpicture}
Where to use it:
Flowcharts, plots, geometric drawings, diagrams, illustrations for scientific or educational material.
9. Bibliography and Citations
LaTeX manages references beautifully.
\usepackage{biblatex}
\addbibresource{references.bib}
According to \cite{einstein1905}, the theory of relativity...
\printbibliography
Where to use it:
Research papers, theses, academic essays, scientific articles.
10. Hyperlinks
Add links and clickable references.
\usepackage{hyperref}
\href{https://example.com}{Click here}
Where to use it:
Digital documents, technical manuals, online publications.
LaTeX code may look intimidating at first, but every command has a specific, practical purpose. Once you understand what each snippet does and when to use it, LaTeX becomes a powerful ally for producing highly professional documents. Whether you are creating a thesis, a scientific article, a presentation, or complex diagrams, these examples give you a solid foundation to start building your projects effectively.