LaTeX Document Structure and Text Formatting Essentials
Document Components and Chinese Typesetting
\documentclassloads the document class- Options for English documents
article: Short documents without chaptersreport: Single-sided documents containing chaptersbook: Double-sided documents containnig chaptersbeamer: Presentation slides
- Options for Chinese documents
ctexartctexrepctexbookctexbeamer
- Options for English documents
\usepackageimports 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*}
- Simplified Chinese:
Use \\ to start a new line without creating a new paragraph.
To fully support Chinese input, follow these steps:
- Add
\usepackage[UTF8]{ctex}to the preamble. - 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
\includecan be managed using\includeonlyto 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
\inputdo not require their owndocumentenvironment.
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
setspacepackage:\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.