跳到主要内容

文档类和选项

文档类定义了文档的整体布局和格式。本章介绍 LaTeX 中常用的文档类及其选项。

文档类概述

文档类通过 \documentclass 命令指定:

\documentclass[options]{class}

标准文档类

article

用于短篇文章、论文、报告:

\documentclass{article}

特点:

  • 没有章节
  • 适合短文档
  • 默认不带封面

report

用于较长的报告、学位论文:

\documentclass{report}

特点:

  • 有章节
  • 适合中长文档
  • 可单独出版

book

用于书籍:

\documentclass{book}

特点:

  • 有章节和部分
  • 左右页不同
  • 适合长文档

letter

用于信函:

\documentclass{letter}

beamer

用于演示文稿:

\documentclass{beamer}

ctexart / ctexrep / ctexbook

中文文档类:

\documentclass{ctexart}    % 中文文章
\documentclass{ctexrep} % 中文报告
\documentclass{ctexbook} % 中文书籍

文档类选项

字体大小

\documentclass[10pt]{article}   % 默认
\documentclass[11pt]{article}
\documentclass[12pt]{article}

纸张大小

\documentclass[a4paper]{article}
\documentclass[a5paper]{article}
\documentclass[b5paper]{article}
\documentclass[letterpaper]{article}

纸张方向

\documentclass[landscape]{article}

单双面

\documentclass[oneside]{article}    % 单面(默认)
\documentclass[twoside]{article} % 双面

单双栏

\documentclass[onecolumn]{article}  % 单栏(默认)
\documentclass[twocolumn]{article} % 双栏

草稿模式

\documentclass[draft]{article}

草稿模式特点:

  • 不加载图片(显示方框)
  • 标记溢出行
  • 加快编译速度

标题页

\documentclass[titlepage]{article}    % 标题单独一页
\documentclass[notitlepage]{article} % 标题不单独一页

章节编号

\documentclass[openright]{book}   % 章节从右页开始
\documentclass[openany]{book} % 章节从任意页开始

组合选项

多个选项用逗号分隔:

\documentclass[12pt, a4paper, twoside]{article}

文档结构命令

标题信息

\title{文档标题}
\author{作者姓名}
\date{2024年1月1日}
% 或
\date{\today}

\maketitle % 生成标题

章节命令

article 类

\section{节}
\subsection{小节}
\subsubsection{子小节}
\paragraph{段落}
\subparagraph{子段落}

report 和 book 类

\part{部分}
\chapter{章}
\section{节}
\subsection{小节}
\subsubsection{子小节}

章节编号控制

\section*{无编号节}           % 不编号
\setcounter{section}{0} % 重置计数器
\addcontentsline{toc}{section}{标题} % 添加到目录

页面布局

geometry 宏包

\usepackage{geometry}

\geometry{
a4paper,
left=2.5cm,
right=2.5cm,
top=2.5cm,
bottom=2.5cm
}

页面样式

\pagestyle{plain}     % 页码在底部
\pagestyle{headings} % 页眉显示章节
\pagestyle{empty} % 无页眉页脚
\thispagestyle{empty} % 当前页无页眉页脚

目录

生成目录

\tableofcontents    % 目录
\listoffigures % 图目录
\listoftables % 表目录

目录深度

\setcounter{tocdepth}{2}    % 目录深度
\setcounter{secnumdepth}{3} % 编号深度

文档类对比

特性articlereportbook
章节
部分
标题页可选
摘要
适用短文报告书籍

示例文档

文章

\documentclass[12pt, a4paper]{article}

\usepackage{ctex}
\usepackage{geometry}
\geometry{margin=2.5cm}

\title{文章标题}
\author{作者}
\date{\today}

\begin{document}

\maketitle

\begin{abstract}
这是摘要内容。
\end{abstract}

\tableofcontents

\section{引言}
正文内容。

\section{方法}
正文内容。

\section{结论}
正文内容。

\end{document}

报告

\documentclass[12pt, a4paper]{report}

\usepackage{ctex}

\title{报告标题}
\author{作者}
\date{\today}

\begin{document}

\maketitle

\tableofcontents

\chapter{绪论}
\section{研究背景}
正文内容。

\chapter{研究方法}
正文内容。

\chapter{结论}
正文内容。

\end{document}

书籍

\documentclass[12pt, a4paper]{book}

\usepackage{ctex}

\title{书籍标题}
\author{作者}
\date{\today}

\begin{document}

\frontmatter % 前言部分
\maketitle
\tableofcontents

\mainmatter % 正文部分
\part{第一部分}
\chapter{第一章}
正文内容。

\chapter{第二章}
正文内容。

\part{第二部分}
\chapter{第三章}
正文内容。

\backmatter % 附录部分
\appendix
\chapter{附录}
附录内容。

\end{document}

Beamer 演示文稿

\documentclass{beamer}

\usepackage{ctex}

\title{演示文稿标题}
\author{作者}
\date{\today}

\begin{document}

\begin{frame}
\titlepage
\end{frame}

\begin{frame}{目录}
\tableofcontents
\end{frame}

\section{第一部分}
\begin{frame}{第一页标题}
内容要点:
\begin{itemize}
\item 要点一
\item 要点二
\item 要点三
\end{itemize}
\end{frame}

\section{第二部分}
\begin{frame}{第二页标题}
更多内容。
\end{frame}

\end{document}

小结

本章介绍了 LaTeX 文档类:

  • 标准文档类:article、report、book、letter、beamer
  • 中文文档类:ctexart、ctexrep、ctexbook
  • 文档类选项:字体大小、纸张大小、单双面等
  • 文档结构命令:标题、章节、目录
  • 页面布局:geometry 宏包、页面样式

选择合适的文档类是创建专业文档的第一步。下一章将介绍基础语法。