I'd like to change the way appendix section headings appear with KOMA-Script. I can achieve the behaviour I want by manually patching the \begin{appendices}...
with a \renewcommand{\sectionlinesformat}
, but I'd like to use xpatch
instead and handle it in my document's pramble. I know that my patch works because I am successfully changing a \cref
alias with it. Under the %%%% ATTEMPTS SHOWN BELOW
comment are two chunks of code I've tested that do not work. The errors are missing number treated as 0 and illegal unit of measurement for both attempts (without and with using the @hangfrom), and I additionally get something's wrong, perhaps missing an item with the @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}
\appendix
is a switch.