我想用 KOMA-Script 更改附录部分标题的显示方式。我可以通过使用 手动修补 来实现我想要的行为\begin{appendices}...
,\renewcommand{\sectionlinesformat}
但我想改用xpatch
并在文档的 pramble 中处理它。我知道我的补丁有效,因为我成功地用\cref
它更改了别名。%%%% ATTEMPTS SHOWN BELOW
注释下是我测试过的两段不起作用的代码。错误是两次尝试(不使用和使用 @hangfrom)都缺少被视为 0 的数字和非法的测量单位,而且我还遇到了一些错误,可能是 @hangfrom 缺少一个项目。
\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
\usepackage{xpatch}
\crefname{appsec}{Appendix}{Appendices}
%%%% ATTEMPTS SHOWN BELOW
%\makeatletter
\xapptocmd\appendices{%
\crefalias{section}{appsec}
%%%% Test 1 does not work
% \renewcommand{\sectionlinesformat}[4]{% change appendix format
% \hskip #2#3\\#4%
% }
%%%% Test 2 does not work
% \renewcommand{\sectionlinesformat}[4]{% change appendix format
% \@hangfrom{\hskip #2#3}#4%
% }
}{}{\PatchFailed}
%\makeatother
\begin{document}
\tableofcontents
\section{Some section with number in the margin}
Reference to \cref{appa}
\begin{appendices}
\section{Something appended} \label{appa}
%%% Test: this works
%% \renewcommand{\sectionlinesformat}[4]{% change appendix format
%% \hskip #2#3\\#4%
%% }
Test appendix
\end{appendices}
\end{document}
答案1
使用别名:
\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
\usepackage{xpatch}
\crefname{appsec}{Appendix}{Appendices}
\xapptocmd\appendices{%
\crefalias{section}{appsec}%
\let\sectionlinesformat\modifiedsectionlinesformat
}{}{}
\makeatletter
\newcommand{\modifiedsectionlinesformat}[4]{% change appendix format
\@hangfrom{\hskip #2#3}#4%
}
\makeatother
\begin{document}
\tableofcontents
\section{Some section with number in the margin}
Reference to \cref{appa}
\begin{appendices}
\section{Something appended} \label{appa}
Test appendix
\end{appendices}
\end{document}