TheNetAdmin / zjuthesis

Zhejiang University Graduation Thesis LaTeX Template
https://thenetadmin.github.io/zjuthesis
MIT License
2.56k stars 601 forks source link

解决方案:中途修改目录级别 #399

Closed TesiLin closed 5 months ago

TesiLin commented 5 months ago

可改进的内容

我们学院要求final版本的目录中,paper和proposal两部分的目录级别不同。 其中,paper部分的目录与现有的一致,但proposal的目录应该仅到下图所示的层级,也就是chapter等级。

image

代码与步骤

参考了Switching tocdepth in the middle of a document,在zjuthesis中应当修改的东西如下:

config/commands.tex,增加命令

\newcommand{\changelocaltocdepth}[1]{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{#1}}%
  \setcounter{tocdepth}{#1}%
}

zjuthesis.tex,修改\newcommand{\inputundergraduate}\equal{\Period}{final},在proposal部分增加一行\changelocaltocdepth{0}。完整如下:

    \ifthenelse{\equal{\Period}{final}}
    {
        % Final thesis
        % Final part
        \newcommand{\undergradcurrstage}{final}
        \newrefsection

        \coverstyle
        \inputpage{final}{cover}

        \prevstyle
        \inputpage{final}{previous}
        \inputpage{final}{toc}

        \bodystyle
        \inputpage{final}{cover-part}

        \resetpagecounter{}
        \inputbody{final/content}
        \inputbody{final/post}

        \poststyle
        \inputpage{final}{post}

        % Proposal part
        \renewcommand{\undergradcurrstage}{proposal}
        \newrefsection

        \changelocaltocdepth{0} % 使得第二部分只输出第一级标题

        \coverstyle
        \inputpage{proposal}{cover-part}
        \inputpage{proposal}{cover}
        \inputpage{proposal}{previous}

        \bodystyle
        \inputbody{proposal/content}

        \poststyle
        \inputpage{proposal}{post}
    }

预期结果

渲染结果如下:

  1. 目录 image

  2. 文章中以“二、开题报告”为例,子标题都仍然存在且有编号。 image

比起利用加号的方式(例如`\chapter{}),保留了标题编号,且不需要手动\addtocontents`编辑目录。

TesiLin commented 5 months ago

发现有前辈增加过\changelocaltocdepth命令了,打扰了