Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

LaTeX Document Structure and Text Formatting Essentials

Tech May 14 13

Document Components and Chinese Typesetting

  • \documentclass loads the doucment class
    • Options for English documents
      • article: Short documents without chapters
      • report: Single-sided documents containing chapters
      • book: Double-sided documents containing chapters
      • beamer: Presentation slides
    • Options for Chinese documents
      • ctexart
      • ctexrep
      • ctexbook
      • ctexbeamer
  • \usepackage imports packages to add or modify LaTeX functionality
    • \usepackage{CJKutf8} enables Chinese character support
  • \begin{document} and \end{document} define the content body
    • Simplified Chinese: \begin{CJK*}{UTF8}{gbsn} and \end{CJK*}
    • Traditoinal Chinese: \begin{CJK*}{UTF8}{bsmi} and \end{CJK*}

Use \\ to start a new line without creating a new paragraph.

To fully support Chinese input, follow these steps:

  1. Add \usepackage[UTF8]{ctex} to the preamble.
  2. Switch the compiler to XeLaTeX.

Font Styles

Example: \textbf{Together for a Shared Future}

Text Command Effect Declaration Command
\textrm Serif \rmfamily
\textbf Bold \bfseries
\textit Italic \itshape
\texttt Monospace \ttfamily
\textsf Sans-serif \sffamily
\textsc Small Caps \scshape
\textsl Slanted \slshape

LaTeX typically avoids explicit styling commands, favoring logical markup. For instance, \emph is used to emphasize text semantically.

Font Sizes

Example: {\bfseries\Large Together for a Shared Future\par}

Command Description
\tiny Tiny
\scriptsize Script size
\footnotesize Footnote size
\small Small
\normalsize Normal
\large Large
\huge Huge

Note: Always use \par to explicitly end the scope before changing the size back; otherwise, the line spacing of subsequent lines may render incorrectly.

Lists

Unordered List


\documentclass{ctexart}
\begin{document}
\begin{itemize}
\item First item
\item Second item
\item Third item
\end{itemize}
\end{document}

Ordered List


\documentclass{ctexart}
\begin{document}
\begin{enumerate}
\item First item
\item Second item
\item Third item
\end{enumerate}
\end{document}

Description List


\documentclass{ctexart}
\begin{document}
\begin{description}
\item[First] Description text
\item[Second] Description text
\item[Third] Description text
\end{description}
\end{document}

Sectioning Structure

Command Meaning
\chapter Chapter
\section Section
\subsection Subsection
\subsubsection Subsubsection
\part Part
\paragraph Paragraph
\subparagraph Subparagraph

Document Organization

Command Description
\tableofcontents Generates a table of contents
\setcounter{tocdepth}{level} Sets the depth of sections displayed in TOC
\section[Short Title]{Long Title} Uses a shorter title in the TOC
\section*{Title} Section title excluded from the TOC

include vs input

Both commands insert external TEX files using relative paths.

  • \include: Starts on a new page and performs internal adjustments; best used for top-level structures like chapters.
  • Files inserted via \include can be managed using \includeonly to select which parts to compile.

\documentclass{ctexrep}
\includeonly{intro,conclusion}
\begin{document}
\tableofcontents
\include{intro}
\include{conclusion}
\end{document}
  • \input: Inserts the source code exactly as-is.
  • Sub-files loaded with \input do not require their own document environment.

Underlines and Wavy Lines

Requires package: \usepackage{ulem}

Command Effect
\uline{Text here} Single underline
\uuline{Text here} Double underline
\uwave{Text here} Wavy line
\sout{Text here} Strikethrough
\xout{Text here} Slashed strikethrough

Spacing

  • Standard spaces
    • Consecutive spaces in the source are collapsed into one.
    • A line break at the end of a line is treated as a space.
  • Fixed-width spaces
    • \quad: 1em (width of "M")
    • \qquad: 2em
    • \enspace: 0.5em
    • \, or \thinspace: ~3/18 em
    • \medspace: ~4/18 em
    • \thickspace: ~5/18 em
  • Non-breaking and stretchable spaces
    • \ (backslash + space): Standard space after commands.
    • ~: Non-breaking space (e.g., Fig.~3).
    • \hspace{length}: Custom horizontal space (e.g., \hspace{2cm}).
    • \hspace*{length}: Resistant to line breaks.
    • \hfill: Expands to fill available horizontal space.
  • Math mode spaces
    • \,, \:, \;: Increasing width.
    • \!: Negative space.
  • Paragraph and line spacing
    • Empty line in source: Starts a new paragraph.
    • \setlength{\parskip}{1em}: Sets paragraph gap.
    • \setlength{\baselineskip}{1.5em}: Sets line height.
    • Using setspace package: \onehalfspacing, \doublespacing, \singlespacing.
  • Vertical spaces
    • \vspace{length}: Custom vertical space.
    • \vspace*{length}: Resistant to page breaks.
    • \vfill: Expands to fill available vertical space.
  • Phantom spaces
    • \hphantom{content}: Horizontal space equal to content width.
    • \vphantom{content}: Vertical space equal to content height.
    • \phantom{content}: Both width and height.
Tags: latex

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.