我正在使用scrartcl
并尝试将目录中的附录上移一级,以便将它们格式化为小节而不是节。
我已将我的解决方案改编自这问题和我当前的 MWE (min.tex) 如下所示:
\documentclass{scrartcl}
\usepackage[page]{appendix} % better appendices: \begin{appendices}
\usepackage{etoolbox} % needed for code below (\AtBeginEnvironment)
\AtBeginEnvironment{appendices}{%
\addappheadtotoc % add Appendices to toc
\makeatletter
\addtocontents{toc}{% % move appendix sections one level up in toc
\begingroup % make sure we reset section level redefinition after appendices
\let\protect\l@section\protect\l@subsection
\let\protect\l@subsection\protect\l@subsubsection}}
\AtEndEnvironment{appendices}{%
\addtocontents{toc}{\endgroup}} % reset section level redefinition
\begin{document}
\tableofcontents
\begin{appendices}
\section{Variablen}
\section{Tabellen}
\end{appendices}
\end{document}
第二次使用lualatex编译获取目录的时候出现以下错误:
) (./min.toc
! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.3 ...tsline {section}{\numberline {A}Variablen}{1}
查看 min.toc,原因就一目了然了。命令中添加了虚假空格
\begingroup \let \l @section\l @subsection \let \l @subsection\l @subsubsection
应为
\begingroup \let \l@section\l@subsection \let \l@subsection\l@subsubsection
当我在它工作正常\let
之后添加命令时\begin{appendices}
。所以我怀疑是\AtBeginEnvironment
添加了那些空格。我宁愿将其保留在序言中,而不是将其放在主文档中。有办法解决这个问题吗?
更新
我认为,下面描述的格式问题在接受的答案中比我在此处的编辑更优雅地修复了。我建议使用它。但我会将我的修复保留下来以供记录。
以下答案和上述问题的解决方案以及 cgnieder 在评论中的修复与appendix
包的“附录”标题存在不一致问题。为了使其适应 中使用的部分的格式,必须重新编辑scrartcl
命令(从\@sec@pppage
appendix
包裹):
\makeatletter
\renewcommand{\@sec@pppage}{%
\par
\addvspace{4ex}%
\@afterindentfalse
{\parindent \z@ \raggedright
\interlinepenalty \@M
% the following line was changed from the original
\usekomafont{disposition} \usekomafont{section} \appendixpagename%
\markboth{}{}\par}%
\if@dotoc@pp
\addappheadtotoc
\fi
\nobreak
\vskip 3ex
\@afterheading
}
\makeatother
这段代码可能有点过头了,但它确实有效。不幸的是,我的 LaTeX 编程技能还不够好。也许有人有更好的解决方案?
答案1
一种无需\AtBeginEnvironment
分组的解决方案,通过稍微重新定义appendices
环境并暂时让其\section
与\subsection
编辑
subappendices
包中已经有一个环境appendix
。使用该环境可能比修改环境更好appendices
。但是,此解决方案展示了两种方法。
事实上,像\begin{appendices} introduces a strange,
\part - like heading for the appendix is due to the
[page] option. Removing that and adding a more appropiate
\section*` 这样的标题可以解决这个问题。
\documentclass{scrartcl}
\usepackage{appendix} % better appendices: \begin{appendices}
\usepackage{etoolbox} % needed for code below (\AtBeginEnvironment)
\usepackage{letltxmacro}%
\LetLtxMacro\StandardAppendixBegin\appendices
\LetLtxMacro\StandardAppendixEnd\endappendices%
\renewenvironment{appendices}{%
\setcounter{subsection}{0}%
\section*{\appendixname}
\addcontentsline{toc}{section}{\appendixname}%
\StandardAppendixBegin%
\renewcommand{\thesubsection}{\Alph{subsection}}
\LetLtxMacro\section\subsection%
}{\StandardAppendixEnd\setcounter{subsection}{0}}%
%% Adding the automatic heading for subappendices%
\AtBeginEnvironment{subappendices}{%
\section*{\appendixname}%
\addcontentsline{toc}{section}{\appendixname}%
\renewcommand{\setthesubsection}{\Alph{subsection}}%
}%
\begin{document}
\tableofcontents
\section{Real Section}
\subsection{A real subsection}
\begin{appendices}%
\subsection{Variablen -- changed appendices environment}
\subsection{Tabellen -- changed appendices environment}
\end{appendices}%
\begin{subappendices}
\subsection{Variablen -- subappendices environment}
\subsection{Tabellen -- subappendices environment}
\end{subappendices}
\section{Another real section}
\end{document}