Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

LaTeX Document Structure and Text Formatting Essentials

Tech May 14 2

Document Components and Chinese Typesetting

  • \documentclass loads the document class
    • Options for English documents
      • article: Short documents without chapters
      • report: Single-sided documents containing chapters
      • book: Double-sided documents containnig 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*}
    • Traditional 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}

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}

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

Document Organization

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}

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.