This comprehensive guide covers LaTeX document organization, creating reusable templates, custom document classes, and best practices for maintaining professional documents.
Document Structure
Basic Article Template
% article-template.tex
\documentclass[12pt,a4paper]{article}
% Package imports
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
% Custom commands
\newcommand{\R}{\mathbb{R}}
% Title information
\title{Document Title}
\author{Author Name}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
Document abstract goes here.
\end{abstract}
\section{Introduction}
\label{sec:introduction}
Introduction content.
\section{Methods}
\label{sec:methods}
Methods content.
\section{Results}
\label{sec:results}
Results content.
\section{Conclusion}
\label{sec:conclusion}
Conclusion content.
% Bibliography
\bibliographystyle{plain}
\bibliography{references}
\end{document}
Basic Report Template
% report-template.tex
\documentclass[12pt,a4paper]{report}
\usepackage{geometry}
\geometry{margin=1in}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{hyperref}
\title{Report Title}
\author{Author Name}
\date{\today}
\begin{document}
% Title page
\begin{titlepage}
\begin{center}
\vspace*{1in}
{\Huge\bfseries Report Title\par}
\vspace{1in}
{\LARGE Author Name\par}
\vspace{0.5in}
{\large Institution\par}
\vspace{0.5in}
{\large \today\par}
\end{center}
\end{titlepage}
% Abstract
\begin{abstract}
Report abstract here.
\end{abstract}
% Table of contents
\tableofcontents
% Chapters
\chapter{Introduction}
\chapter{Background}
\chapter{Methodology}
\chapter{Results}
\chapter{Conclusion}
% Bibliography
\bibliographystyle{plain}
\bibliography{references}
% Appendices
\appendix
\chapter{Appendix A}
\chapter{Appendix B}
\end{document}
Book Template
% book-template.tex
\documentclass[12pt]{book}
\usepackage{makeidx}
\makeindex
\usepackage{imakeidx}
\usepackage[totoc]{idxlayout}
\usepackage{geometry}
\geometry{margin=1.5in}
\title{Book Title}
\author{Author Name}
\begin{document}
\frontmatter
\maketitle
\tableofcontents
\listoffigures
\listoftables
\include{preface}
\mainmatter
\include{chapter1}
\include{chapter2}
\include{chapter3}
\backmatter
\bibliographystyle{plain}
\bibliography{references}
\printindex
\end{document}
Custom Document Classes
Creating a .cls File
% myarticle.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myarticle}[2024/01/01 Custom Article Class]
% Pass options to article class
\DeclareOption*{
\PassOptionsToClass{\CurrentOption}{article}
}
\ProcessOptions\relax
% Load base class
\LoadClass{article}
% Custom page size
\RequirePackage{geometry}
\geometry{a4paper,margin=1in}
% Custom fonts
\RequirePackage[T1]{fontenc}
\RequirePackage{mathptmx}
% Custom section formatting
\RequirePackage{titlesec}
\titleformat{\section}
{\Large\bfseries}
{\thesection}{1em}{}
% Custom commands
\newcommand{\email}[1]{\hrefmailto:#1}
\newcommand{\website}[1]{\href{#1}{#1}}
% Bibliography style
\RequirePackage[numbers]{natbib}
\bibliographystyle{plainnat}
% End of class file
\endinput
Using Custom Class
% Use custom class
\documentclass{myarticle}
\title{My Document}
\author{John Doe}
\begin{document}
% Document content
\end{document}
Custom Package Files
Creating a .sty File
% mypackages.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackages}[2024/01/01 Custom Packages]
% Math packages
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{mathtools}
% Graphics
\RequirePackage{graphicx}
\RequirePackage{tikz}
% Hyperlinks
\RequirePackage{hyperref}
% Custom math operators
\DeclareMathOperator{\trace}{tr}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\Span}{Span}
% Custom commands
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Z}{\mathbb{Z}}
% Theorem environments
\RequirePackage{amsthm}
\newtheorem*{theorem}{Theorem}
\newtheorem*{lemma}{Lemma}
\newtheorem*{definition}{Definition}
% End of package
\endinput
Using Custom Package
% Document using custom package
\documentclass{article}
\usepackage{mypackages}
\begin{document}
% Document content
\end{document}
Reusable Components
Title Page Templates
% Custom title page
\begin{titlepage}
\sffamily
\begin{center}
% University logo
\vspace{0.5in}
\ifdefined\includegraphics
\includegraphics[width=3in]{university-logo.pdf}
\fi
\vspace{1in}
% Title
{\Huge\bfseries \@title \par}
\vspace{0.5in}
% Subtitle
{\Large \@subtitle \par}
\vspace{1in}
% Author
{\LARGE \@author \par}
\vspace{0.5in}
% Institution
{\large \@institute \par}
\vspace{1in}
% Date
{\large \@date \par}
\end{center}
\end{titlepage}
Chapter Template
% chapter-template.tex
\chapter{Introduction}
\label{chap:introduction}
\section{Background}
\label{sec:background}
% Content here
\section{Objectives}
\label{sec:objectives}
\begin{enumerate}
\item Objective 1
\item Objective 2
\item Objective 3
\end{enumerate}
\section{Scope}
\label{sec:scope}
% Content here
Project Organization
Directory Structure
project/
โโโ main.tex % Main document
โโโ chapters/
โ โโโ introduction.tex
โ โโโ methods.tex
โ โโโ results.tex
โ โโโ conclusion.tex
โโโ figures/
โ โโโ figure1.pdf
โ โโโ figure2.png
โโโ tables/
โ โโโ table1.tex
โโโ references/
โ โโโ references.bib
โโโ style/
โ โโโ mypackages.sty
โ โโโ mytheme.sty
โโโ output/
โโโ main.pdf
Main Document Structure
% main.tex
\documentclass[12pt]{book}
% Preamble
\usepackage{import}
\usepackage{graphicx}
\graphicspath{{figures/}}
% Import packages
\usepackage{mypackages}
% Custom imports
\import{style}{mypackages}
\begin{document}
% Front matter
\frontmatter
\import{chapters}{title}
\tableofcontents
\listoffigures
\listoftables
% Main matter
\mainmatter
\import{chapters}{introduction}
\import{chapters}{methods}
\import{chapters}{results}
\import{chapters}{conclusion}
% Back matter
\backmatter
\bibliographystyle{plain}
\bibliography{references/references}
\end{document}
Using import Package
% For chapter-level imports
\usepackage{import}
% Import a chapter file
\chapter{Introduction}
\label{chap:intro}
\import{sections}{intro-motivation}
\import{sections}{intro-background}
% With relative paths
\subimport{}{sections/intro}
\subimport{chapter1}{main}
Best Practices
Package Management
% Recommended package order
% 1. Document class
\documentclass[12pt]{article}
% 2. Font encoding
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% 3. Core math
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
% 4. Graphics
\usepackage{graphicx}
\usepackage{tikz}
% 5. Tables
\usepackage{booktabs}
\usepackage{array}
% 6. References
\usepackage{hyperref}
\usepackage{cleveref}
% 7. Layout
\usepackage{geometry}
% 8. Typography
\usepackage{microtype}
Avoid Package Conflicts
% Load packages in correct order
\usepackage{hyperref} % Load last (most conflicts)
\usepackage{cleveref} % After hyperref
% Or use options
\usepackage[pdfborder={0 0 0}]{hyperref}
% Define packages before settings
\usepackage{amsmath}
\usepackage{natbib}
% Don't redefine after loading
Custom Commands Best Practices
% Use descriptive names
\newcommand{\mycommand}{\text{something}}
\newcommand{\definition}{\textbf}
\newcommand{\code}{\texttt}
% Document your commands
% Usage: \concept{term} - bold term
\newcommand{\concept}[1]{\textbf{#1}}
% Use \providecommand if conditional
\providecommand{\mycommand}[1][default]{#1}
% For math, use \DeclareMathOperator
\DeclareMathOperator{\grad}{\nabla}
\DeclareMathOperator{\divergence}{\nabla\cdot}
Academic Templates
Thesis Template
% thesis.tex
\documentclass[12pt,twoside]{book}
\usepackage{geometry}
\geometry{margin=1.5in}
\usepackage{fancyhdr}
\pagestyle{fancy}
% Chapter style
\usepackage{titlesec}
\titleformat{\chapter}
{\Huge\bfseries}
{\thechapter}{1em}{}
\begin{document}
\frontmatter
\title{Thesis Title}
\author{Author Name}
\date{2024}
\maketitle
\begin{abstract}
Thesis abstract.
\end{abstract}
\tableofcontents
\listoffigures
\listoftables
\mainmatter
\chapter{Introduction}
% Content
\chapter{Literature Review}
% Content
\chapter{Methodology}
% Content
\chapter{Results}
% Content
\chapter{Discussion}
% Content
\chapter{Conclusion}
% Content
\backmatter
\bibliographystyle{plain}
\bibliography{references}
\end{document}
CV/Resume Template
% cv.tex
\documentclass[11pt,a4paper]{article}
\usepackage{geometry}
\geometry{margin=2cm}
\usepackage{enumitem}
\begin{document}
\begin{center}
{\Huge\textbf{John Doe}}\par
\bigskip
Email: [email protected] \quad Phone: (123) 456quad Website: johndoe-7890 \.com
\end{center}
\section{Education}
\textbf{Ph.D. in Computer Science} \hfill 2020-2024
\newline
University of Example
\begin{itemize}
\item Thesis: ``Advanced Topics in Machine Learning''
\item GPA: 4.0/4.0
\end{itemize}
\textbf{B.S. in Computer Science} \hfill 2016-2020
\newline
University of Sample
\section{Experience}
\textbf{Research Assistant} \hfill 2022-2024
\newline
AI Lab, University of Example
\section{Publications}
\begin{enumerate}
\item J. Doe, ``Paper Title,'' Journal Name, 2024.
\end{enumerate}
\end{document}
Cover Letter Template
% cover-letter.tex
\documentclass[12pt]{letter}
\usepackage{geometry}
\geometryin}
\signature{John{margin=1 Doe}
\address{123 Main Street \\ City, State 12345}
\begin{document}
\begin{letter}
{Company Name \\ 456 Business Ave \\ City, State 67890}
\opening{Dear Hiring Manager,}
I am writing to apply for the position of Software Engineer.
Body of letter goes here.
\closing{Sincerely,}
\end{letter}
\end{document}
Version Control
Git Ignore for LaTeX
# LaTeX build files
*.aux
*.bbl
*.blg
*.log
*.out
*.toc
*.lot
*.lof
# Build directories
_build/
*.pdf
# Editor files
*.swp
*.swo
*~
.DS_Store
Git Workflow
# Track main .tex files
git add main.tex chapters/*.tex
# Track figures (if small)
git add figures/
# Track bibliography
git add references/
# Ignore build outputs
echo "*.aux" >> .gitignore
echo "*.pdf" >> .gitignore
Performance Optimization
Draft Mode
% Fast compilation for drafts
\documentclass[draft]{article}
\usepackage[draft]{graphicx}
% Or set at runtime
\ifdraft{
\documentclass[draft]{article}
}{
\documentclass{article}
}
Partial Compilation
% Compile only selected chapters
\includeonly{
chapters/introduction,
chapters/methods
}
External Resources
Related Articles
- Comprehensive Guide to Bibliography Management
- Mathematical Typesetting in LaTeX
- Creating Presentations with Beamer
Comments