![通过 KOMA 脚本为附录部分标题设置不同的样式](https://linux22.com/image/401634/%E9%80%9A%E8%BF%87%20KOMA%20%E8%84%9A%E6%9C%AC%E4%B8%BA%E9%99%84%E5%BD%95%E9%83%A8%E5%88%86%E6%A0%87%E9%A2%98%E8%AE%BE%E7%BD%AE%E4%B8%8D%E5%90%8C%E7%9A%84%E6%A0%B7%E5%BC%8F.png)
我喜欢在页边空白处悬挂章节编号。但是当我移至附录时,我希望将行为恢复正常。
此外,我想在新行上开始附录的名称(但不在目录中),例如:
附录 A
附加内容
下面是一个有问题的 MWE,但 cref 和所有内容,除了悬挂的附录 X 问题,并且附录 X 和附录名称之间缺少换行符:
\documentclass[12pt,
twoside=false,
letterpaper,
hidelinks,
parskip=half+,
%onehalfspacing, % see setstrecj after \begin{document}
bibliography=numbered,
numbers=noenddot]{scrartcl}
\renewcommand\sectionlinesformat[4]{% used by free-standing headings with style=section
\makebox[0pt][r]{#3}#4}
%\usepackage{appendix} % use this if you want Appendix in the TOC
\usepackage[titletoc,title]{appendix} % use this if you want Appendix in the TOC
\usepackage{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref} % cref
\crefname{appsec}{Appendix}{Appendices}
\begin{document}
\tableofcontents
\section{Some section with number in the margin}
Reference to \cref{appb}
\begin{appendices}
\crefalias{section}{appsec} %
\section{Something appended} \label{appa}
下面是我的一个 MWE 示例,展示了我的解决方法。这就是我想要的显示方式,但我失去了使用 cref 的能力,如果我想添加子节,编号就会崩溃:
\documentclass[12pt,
twoside=false,
letterpaper,
hidelinks,
parskip=half+,
%onehalfspacing, % see setstrecj after \begin{document}
bibliography=numbered,
numbers=noenddot]{scrartcl}
\renewcommand\sectionlinesformat[4]{% used by free-standing headings with style=section
\makebox[0pt][r]{#3}#4}
%\usepackage{appendix} % use this if you want Appendix in the TOC
\usepackage[titletoc,title]{appendix} % use this if you want Appendix in the TOC
\usepackage{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref} % cref
\crefname{appsec}{Appendix}{Appendices}
\begin{document}
\tableofcontents
\section{Some section with number in the margin}
Reference to \hyperref[appb]{Appendix B}
\section*{Appendix A\\Something appended} \label{appa}
\addcontentsline{toc}{section}{Appendix A Something appended}
\section*{Appendix A\\Another thing appended} \label{appb}
\addcontentsline{toc}{section}{Appendix B Something appended}
\end{document}
答案1
以下是没有包装的建议appendix
:
\documentclass[12pt,
%twoside=false,% default
letterpaper,
hidelinks,
parskip=half+,
bibliography=numbered,
numbers=noenddot
]{scrartcl}
\usepackage{lipsum}
\renewcommand\sectionlinesformat[4]{% used by free-standing headings with style=section
\makebox[0pt][r]{#3}#4}
\providecommand*\appendixname{Appendix}
\newcommand*\originalappendix{}
\let\originalappendix\appendix
\renewcommand\appendix{%
\originalappendix
\renewcommand\sectionformat{\appendixname~\thesection\autodot}
\renewcommand\sectionlinesformat[4]{%
\ifstr{##1}{section}
{##3\\*##4}% sections
{\makebox[0pt][r]{##3}{##4}}% subsections etc.
}%
\renewcommand\addsectiontocentry[2]{%
\addtocentrydefault{appendixsection}{##1}{##2}%
}%
}
\DeclareTOCStyleEntry[
level=\sectiontocdepth,
indent=0pt,
numwidth=1em,
dynnumwidth,
numsep=1em,
entrynumberformat=\entrywithprefix{\appendixname}
]{section}{appendixsection}
\newcommand\entrywithprefix[2]{#1~#2}
\usepackage{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref} % cref
\begin{document}
\tableofcontents
\section{Some section with number in the margin}
Reference to \cref{appb}
\appendix
\section{Something appended} \label{appa}
\lipsum[2]
\section{Another thing appended} \label{appb}
\lipsum[2]
\subsection{Subsection in appendix}
\lipsum[3]
\end{document}
运行三次即可获得
答案2
我发现了一个可能被认为不够优雅的解决方案,但它对我来说很有效,并且我可以使用问题中显示的第一个代码块的结构(在其中我可以利用包appendices
并使用titletoc
和title
键)。
我简单查看了 KOMA-Script 手册,找到了 的默认定义,并在 开始后\sectionlinesformat
立即重新陈述(省略) ,并添加了如下换行符。\@hangfrom
appendices
\begin{appendices}
\renewcommand{\sectionlinesformat}[4]{%
\hskip #2#3\\#4%
}
\section{Something appended} \label{appa}
\end{appendices}
我想在开始环境时自动包含这个命令是一种更好的做法appendices
,也许xpatch
是可行的方法。