latex自动生成中文目录_如何调整目录格式?

该博客介绍了如何在 LaTeX 文档中自动生成并调整中文目录格式,包括使用 ctexbook 宏包、定制章节标题样式、设置浮动图表标题以及调整目录深度等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

更改 document.tex 如下

```tex

% 用 xelatex 编译

\documentclass[UTF8,openright]{ctexbook}

\usepackage{pdfpages}

\newcommand{\RELESE}{} % 非盲审版本

\newcommand{\NOMARK}{} % 删除自用标记

\newcommand{\SIGNED}{} % 声明页前面

\ifdefined\RELESE

\newcommand{\ssinfo}[1]{#1}

\else

\newcommand{\ssinfo}[1]{}

\fi

% 论文版面要求:

% 统一按 word 格式A4纸(页面设置按word默认值)编排、打印、制作。

% 正文内容字体为宋体;字号为小4号;字符间距为标准;行距为25磅(约0.88175cm)。

% 页面设置

\usepackage[a4paper,top=2.54cm,bottom=2.54cm,left=3.17cm,right=3.17cm,includehead,includefoot]{geometry}

\setlength{\parindent}{2em}

\setlength{\parskip}{0.5em}

% 章节 标题 设置

\ctexset{

contentsname={\centerline{目\ 录}},

listfigurename={\centerline{插\ 图}},

listtablename={\centerline{表\ 格}},

bibname={},

chapter={

name={第,章},

number=\chinese{chapter},

nameformat={\zihao{3}\bfseries},

titleformat={\zihao{3}\bfseries},

beforeskip={-10pt},

afterskip={20pt}

},

section={

format=\raggedright,

nameformat={\zihao{4}\bfseries},

titleformat={\zihao{4}\bfseries},

afterskip={1ex plus 0.2ex}

},

subsection={

format=\raggedright,

nameformat={\zihao{-4}\bfseries},

titleformat={\zihao{-4}\bfseries},

afterskip={0.5ex plus 0.1ex}

}

}

% 中英文字体

\setmainfont{Times New Roman}

\setCJKfamilyfont{STSong}{STZhongsong}\newcommand{\STSong}{\CJKfamily{STSong}}

\setCJKmonofont{STKaiti}% mac 下面仿宋是坏的

\input{mydefs.tex}

% 浮动图表的标题

\usepackage[margin=2em,labelsep=space,skip=0.5em,font=normalfont]{caption}

\DeclareCaptionFormat{mycaption}{{\heiti\color{blue} #1}#2{\kaishu #3}}

\captionsetup{format=mycaption,tablewithin=chapter,figurewithin=chapter}

% 2020-03-22 add by OsbertWang for https://wenda.latexstudio.net/q-1933.html

\renewcommand{\thefigure}{\arabic{chapter}-\arabic{figure}}

\renewcommand{\cftfigpresnum}{图 }

\renewcommand{\cftfigaftersnum}{}

\newlength{\extralen}

\settowidth{\extralen}{\cftfigpresnum\cftfigaftersnum}

\addtolength{\cftfignumwidth}{\extralen}

% 其他

\usepackage{ulem}

\usepackage{caption}

\usepackage{mathrsfs}

\usepackage{multirow}

\usepackage{url}

\def\ULthickness{1pt}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 在编译前替换掉 u0008 字符

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifmacosx

\immediate\write18{sh u0008.sh}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%% ===== 格式

\input{sty/format.tex}

\zihao{-4}

%------------------ 盲审敏感信息 ------------------------

\ifdefined\RELESE

\csupervisor{xx}

\cauthor{xx}

\def\ccauthor{xx}

\studentid{xx}

\esupervisor{xx}

\eauthor{xx}

\else

\csupervisor{}

\cauthor{}

\def\ccauthor{}

\studentid{}

\esupervisor{}

\eauthor{}

\fi

%-------------------------------------------------------

% 中文封面信息

\graduateyear{2020} % 毕业年份

% \class{O175.29; TP311.1} % 分类号

\class{} % 分类号

\ctitle{\uline{xx}}

\def\cctitle{xx} % 在原创性声明中使用, 不能出现手工换行

\caffil{xx}

\cmajor{xx} % 计算数学

\cdirection{xx} % 数值代数

\cdate{2020 年 5 月}

% 英文封面信息

\etitle{xx}

\eaffil{xx}

\emajor{xx}

\edirection{xx}

\edate{May, 2020}

% 生成封面

%\newgeometry{top=2.0cm,bottom=2.0cm,left=2.5cm,right=2.5cm}

%{

%\renewcommand{\baselinestretch}{1.6}

%\makecover

%}

% % 原创性声明与著作权使用声明

% \ifdefined \SIGNED

% \includepdf{fig/signed.pdf}

% \else

% \include{info/Declaration}

% \fi

% \clearpage{\pagestyle{empty}\cleardoublepage}

% % 答辩委员会成员

% \include{info/Committee}

% \clearpage{\pagestyle{empty}\cleardoublepage}

%\frontmatter

%% 中文摘要

%\thispagestyle{plain}

%\include{info/abs_cn}

%\clearpage

%

%% 英文摘要

%\thispagestyle{plain}

%\include{info/abs_en}

%\clearpage\cleardoublepage

%

{

\hypersetup{linkcolor=black}

% 生成目录

\newpage

\setcounter{tocdepth}{1}

\phantomsection

\addcontentsline{toc}{chapter}{目录}

\tableofcontents

\newpage

\phantomsection

\addcontentsline{toc}{chapter}{图目录}

{

% \renewcommand{\addvspace}[1]{}% 可以删除章节空隙

\listoffigures

}

\newpage

\phantomsection

\addcontentsline{toc}{chapter}{表目录}

{

% \renewcommand{\addvspace}[1]{}% 可以删除章节空隙

\listoftables

}

}

% 正文部分

\mainmatter

\linespread{1.4}\selectfont

%\setlength{\baselineskip}{0.88175cm}

\chapter{AA}

\section{A}

\begin{figure}[htb]

\centering

\includegraphics[width=0.8\linewidth]{sty/ecnu_logo}

\caption{A}

\label{fig:meagate}

\end{figure}

\chapter{BB}

\section{B}

\begin{figure}[htb]

\centering

\includegraphics[width=0.8\linewidth]{sty/ecnu_logo}

\caption{B}

\label{fig:meagate}

\end{figure}

%\chapter*{参考文献}

%\addcontentsline{toc}{chapter}{参考文献}

%\bibliographystyle{plain}

%\bibliography{reference}

%

%

%

%

%

%

%\ssinfo{

%% % 致谢

%\input{info/thanks.tex}

%\clearpage

%% {\pagestyle{empty}\cleardoublepage}

%}

%

%% % 研究成果

%\input{info/research.tex}

%\clearpage

%\cleardoublepage

%% {\pagestyle{empty}\cleardoublepage}

\end{document}

```

回答于 2020-03-22 20:17

810d496de5e9ca6a1c5678aee95d9574.png

啸行啸行

### 如何在 LaTeX 中生成中文目录 #### 使用 CTeX 宏包 CTeX 是一个专门为中文支持设计的宏集,能够方便地处理中文文档中的字符编码、字体以及目录等问题。通过加载 `ctex` 或者 `ctexart` 类型的文档类,可以轻松实现中文目录的支持[^3]。 ```latex \documentclass{ctexart} \begin{document} \title{测试文档} \author{作者名} \date{\today} \maketitle \tableofcontents % 自动生成中文目录 \section{第一节} 这是第一个部分的内容。 \subsection{子节一} 这里是子节的部分内容。 \end{document} ``` 上述代码展示了如何利用 `ctexart` 文档类自动生成带有中文标题的目录结构[^1]。 #### 设置 VSCode 编辑器环境 如果使用的是 Visual Studio Code (VSCode),则可以通过调整其配置文件来适配中文目录的需求。具体操作如下: 编辑项目的 settings.json 文件,在其中加入适合本地化的工具链定义[^4]: ```json { "latex-workshop.latex.tools": [ { "name": "xelatex", "command": "xelatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "%DOC%" ] } ], "latex-workshop.latex.recipes": [ { "name": "xeCJK", "tools": ["xelatex"] } ] } ``` 此 JSON 片段指定了 XeLaTeX 工具作为主要处理器,并启用了同步 TeX 功能以便于调试错误消息。 #### 解决 GBK 字符集下的乱码问题 对于某些特定情况下可能出现的中文目录显示异常情况(比如采用旧版编译器或者不兼容的输入法),可尝试手动指定编码格式为 gbk 并重新执行两次 PDFLaTeX 进程完成渲染过程[^5]。 --- ### 注意事项 确保所使用的操作系统已正确安装对应版本的 MiKTeX 或 TexLive 发行版及其扩展组件;同时也要确认 RStudio 或其他 IDE 软件内部参数已被适当修改以匹配目标平台需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值