章节样式环境可以用于附录格式化吗?

章节样式环境可以用于附录格式化吗?

我已开始在论文中添加附录,以整理每个单独\part部分的通用信息,从而使脚本简洁明了。我正在使用KOMA-Script文档类:scrreprt,将appendix包与minitoc我的章节格式样式的包一起使用让我非常头疼,尽管已解决(在我之前提出的问题中)在大多数情况下,结果并不令人满意,因为我无法将其包含\minitoc在附录中。

我的解决方案是手动操作,只需将\chaptername名称更改为附录,将和\thechapter编号更改为\Alph{chapter},然后也进行更改,\setcounter以便将章节字母从所需的位置开始。

这当然意味着我必须将其全部放回附录章节的末尾,以便所有后续章节不受影响。我想知道是否有一种方法可以简单地定义一个环境来设置这些参数(章节 > 附录、章节编号 > 字母、章节计数器),并允许章节计数器在每个重复环境的实例之间继续,这样当我将第一个环境放在第一部分的末尾时,它将被调用Appendix A,一旦我将下一个环境放在第二部分的末尾,它将自动继续从前一个环境的编号开始,从而得到Appendix B

如果通过定义环境来做到这一点相对简单,我会很乐意通过在下面的 MWE 中采用的手动方法来实现它。

\documentclass[
bibliography=totoc,
headings=big,
captions=tableheading,
chapterprefix=true% like in standard class "report"
]{scrreprt}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=3cm]{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{minitoc}
\usepackage{setspace}
\usepackage{lmodern}

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\begin{document}
\dominitoc
\tableofcontents

\addtokomafont{chapterprefix}{\raggedleft}
\addtokomafont{chapter}{\fontsize{30}{38}\selectfont}
\addtokomafont{section}{\huge}
\addtokomafont{subsection}{\Large}
\addtokomafont{subsubsection}{\large}

\renewcommand*{\chapterformat}{%
\mbox{\scalebox{1.5}{\chapappifchapterprefix{\nobreakspace}}%
\scalebox{4}{\color{gray}\thechapter}\enskip}}

\setcounter{chapter}{6}\setcounter{page}{199}
\newpage\setcounter{page}{212}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Introduction}
%%%%%%%%%%%%%%%%%%%%
\chapter{Conclusions}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Summary of Achievements}
\blindtext
\subsection{Papers Submitted}
\blindtext
\subsubsection{I want to go into the TOC}
\blindtext

%%%%%%%%%%%%%%%%%%%% APPENDIX
% Chapter style change for Appendix
\addcontentsline{toc}{part}{Experimental Appendices}
\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}
\renewcommand{\chaptername}{Appendix}

\chapter{Test}

\minitoc

Here goes nothing

\section{Adding it all in}
Done

% Chapter style reset for following chapters
\setcounter{chapter}{7}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\chaptername}{Chapter}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Introduction}
%%%%%%%%%%%%%%%%%%%%
\chapter{The No MiniTOC Chapter}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Unfortunate Problems}
This chapter does not have a minitoc for some reason
\subsection{Still no minitoc}
\blindtext
\subsubsection{I want to go into the TOC}
\blindtext
%%%%%%%%%%%%%%%%%%%%
\chapter{Conclusions}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Summary of Achievements}
\blindtext
\subsection{Papers Submitted}
\blindtext
\end{document} 

答案1

为了满足OP的要求,必须考虑以下方面:

  • 恢复章节编号真的章节

  • 恢复运行附录编号

  • 恢复计数器输出格式

此外,还必须记住

  • 它应该是这样的命令\appendix

    如果是这种情况,恢复设置有点困难,但可以做到,见下文。

  • 它应该是一个环境,比如partappendix 在这种情况下,将设置包装在环境的起始和结束代码部分内,最好受保护\begingroup\endgroup仅恢复环境的结束代码部分中的章节计数器。

附录章节的设置的主要步骤相同,因此我定义了命令\partappendix@@setup,该命令设置相应的值并进行一些重新定义。此命令在 中调用\appendix。但是,当打开新的真实章节时,必须撤消更改,因此我决定,当开始新的章节时,情况就是这样\part,所以我让\part将设置撤消为“标准”值。--> 重新定义\part及其同类。

注意:使用此方法\chapter时一定不能有真正的附加内容。\appendix

使用

\begin{partappendix}[options]{Appendix Name}
\section{First}
\end[partappendix}

允许\chapter在环境之后添加额外的真实命令partappendix,尽管这种情况不太可能发生。

\appendix环境partappendix的选项和参数描述

  • \minitocMiniTOC=true/false --> True(默认)->在附录开头自动使用
  • TOCEntry={} --> 提供一个简短标题作为目录的条目,否则\Appendixname~\thechapter就使用。

\documentclass[%
bibliography=totoc,
headings=big,
captions=tableheading,
chapterprefix=true% like in standard class "report"
]{scrreprt}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=3cm]{geometry}

\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{minitoc}
\usepackage{setspace}
\usepackage{lmodern}


\newcommand{\mk}[1]{%

}%

\usepackage{etoolbox}%
\usepackage{xkeyval}%
\usepackage{blindtext}%  
\usepackage[bookmarksopen=true,bookmarksopenlevel=4]{hyperref}
\usepackage{bookmark}%


\newcounter{resumechaptercounter}%
\newcounter{resumeappendixcounter}%

\makeatletter
% First save some definitions%
\let\LaTeXStandardChapterName\chaptername%
\let\LaTeXStandardTheChapter\thechapter%
\let\LaTeXStandardAppendix\appendix%
\let\LaTeXStandardPart\part%

% Provide the resetting code for some definitions by the renewcommanded \appendix
\newcommand{\part@@pre@mblecode}{%
\renewcommand{\chaptername}{\LaTeXStandardChapterName}%
\renewcommand{\thechapter}{\LaTeXStandardTheChapter}%
\ifnumgreater{\number\value{resumechaptercounter}}{0}{%
\setcounter{chapter}{\number\value{resumechaptercounter}}%
}{}%
}%

%%%% Provide new part code with optional argument
\newcommand{\unstarredpart@opt}[2][]{%
\part@@pre@mblecode%
\LaTeXStandardPart[#1]{#2}%
}%

%%%% Provide new part code without optional argument

\newcommand{\unstarredpart@noopt}[1]{%
\unstarredpart@opt[#1]{#1}%
}%

%%%% Provide a new \part*{} code in order to relax \tableofcontents
\newcommand{\starredpart}[1]{%
\part@@pre@mblecode%
\LaTeXStandardPart*{#1}%
}%


\newcommand{\unstarredpart}{%
\@ifnextchar[{\unstarredpart@opt}{\unstarredpart@noopt}%
}%

%%%% The real redefinition of \part%
%%% Comment it out in order to keep the standard \part behaviour, but
%%% in this case do not use the new \appendix command, only \begin{partappendix} ... \end{partappendix}
\renewcommand{\part}{%
\@ifstar{\starredpart}{\unstarredpart}%
}%




% Create a switch if the minitoc should be enabled in
% an appendix 'chapter' too. 
\newtoggle{MiniTOC}%


\define@boolkey{PartAppendix}{MiniTOC}[true]{%
\ifKV@PartAppendix@MiniTOC%
\toggletrue{MiniTOC}%
\else%
\togglefalse{MiniTOC}%
\fi%
}%

\define@key{PartAppendix}{TOCEntry}[]{%
\def\PartAppendixKVMacroTOCEntry{#1}%
}%

%This is the appendix setup, which stores the current
% chapter counter and changes the \thechapter, name etc.
\newcommand{\partappendix@@setup}[2][]{%
\setkeys{PartAppendix}{MiniTOC=true,#1}%
\setcounter{resumechaptercounter}{\number\value{chapter}}% Backup 
\renewcommand{\chaptername}{\appendixname}
\setcounter{chapter}{\number\value{resumeappendixcounter}}
\renewcommand{\thechapter}{\Alph{chapter}}
\refstepcounter{resumeappendixcounter}%
\phantomsection%
\ifdef{\PartAppendixKVMacroTOCEntry}{%
\chapter[\PartAppendixKVMacroTOCEntry]{#2}%
}{%
\chapter{#2}%
}%
\iftoggle{MiniTOC}{%
  \minitoc
}{}%
}%

% Renew the appendix command
\renewcommand{\appendix}[2][]{%
\partappendix@@setup[#1]{#2}%
}%


\newenvironment{partappendix}[2][]{%
\begingroup%
\appendix[#1]{#2}%
}{%
\endgroup%
\setcounter{chapter}{\number\value{resumechaptercounter}}% Restore the chapter number%
}
\makeatother

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\begin{document}
\dominitoc
\tableofcontents

\addtokomafont{chapterprefix}{\raggedleft}
\addtokomafont{chapter}{\fontsize{30}{38}\selectfont}
\addtokomafont{section}{\huge}
\addtokomafont{subsection}{\Large}
\addtokomafont{subsubsection}{\large}

\renewcommand*{\chapterformat}{%
\mbox{\scalebox{1.5}{\chapappifchapterprefix{\nobreakspace}}%
\scalebox{4}{\color{gray}\thechapter}\enskip}}

\setcounter{chapter}{6}\setcounter{page}{199}
\newpage\setcounter{page}{212}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Introduction}
%%%%%%%%%%%%%%%%%%%%
\chapter{Conclusions}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Summary of Achievements}
\blindtext
\subsection{Papers Submitted}
\blindtext
\subsubsection{I want to go into the TOC}
\blindtext

%%%%%%%%%%%%%%%%%%%% APPENDIX


\begin{partappendix}{Test}


\section{Adding it all in}
Done

\end{partappendix}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\part{Introduction}
%%%%%%%%%%%%%%%%%%%%
\chapter{The no more No MiniTOC Chapter}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Luckily no more unfortunate problems}
This chapter does have a minitoc again
\subsection{Still has a minitoc}
\blindtext
\subsubsection{I want to go into the TOC and there I am}
\blindtext
%%%%%%%%%%%%%%%%%%%%
\chapter{Conclusions}
\dictum[Sun Tzu]{If you know the enemy and you know yourself %\\
you need not fear the results of a hundred battles.}
\minitoc
\section{Summary of Achievements}
\blindtext
\subsection{Papers Submitted}
\blindtext

\begin{partappendix}[TOCEntry={2nd Part Appendix}]{Appendix from second part}

\section{William}
\subsection{Hamlet}%
\subsubsection{Yorick's skull}
\blindtext

\section{Shakespeare}

\end{partappendix}


\appendix[MiniTOC=false]{AnotherAppendix from second part}

\section{Gandalf}
\subsection{Shadowfax}
\section{Frodo}
\subsection{Sting}
\section{Samwise}%
\subsection{Samwise's Uncle}
\subsubsection{Samwise's Art of gardening and cooking rabbits}
\subsubsection{Gollum's distaste of Samwise's cooking arts}%
\part{Dummy part}
\chapter{Dummy chapter}

\appendix{New Appendix from the dummy part}

\section{A dummy appendix section}%

\end{document}

以下是目录、第 8 章起始页(使用 minitoc)和附录 B 的一些屏幕截图

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

笔记尽管我已将混合\appendix\begin{partappendix} ...\end{partappendix}风格作为演示方法,但我不会在生产代码中这样做。出于“安全”考虑,请使用环境。

其他说明:到目前为止我还没有测试过任何可能发生的情况(无论如何谁能做到这一点)

相关内容