1

I like the use of hanging section numbers in the margin. But when I move to the Appendices, I would like to revert the behavior back to normal.

Additionally, I'd like to start the name of the appendix on a new line (but not in the ToC), for example:

Appendix A

Something appended

Below is a MWE with the issue, but cref and everything EXCEPT the hanging Appendix X issue and it is lacking a line break between Appendix X and the name of the appendix:

\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}

And here is a MWE example of my hacky workaround. This is how I want things to appear, but I lose the ability to use cref, and if I want to add subsections the numbering falls apart:

\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}  
2
  • What if I'm using chapters instead of sections in my appendix? What is the key I need to modify?
    – skan
    Sep 16, 2019 at 12:29
  • It would be \othersectionlevelsformat, correct? I am using scrartcl however, and a create my appendices with the section command. Sep 16, 2019 at 15:16

2 Answers 2

1

Here is a suggestion without package 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}

Run three times to get

enter image description here

2
  • I like this solution, thank you. Now, when I switch to scrreprt, it seems to lose the alphabetical numbering in the appendices. Ideally I'd like Appendices to be a chapter and Appendix A, B,... to be sections. Any insight? In my not-so-minimal template, I'm getting numerical subsection numbers as well... I am trying to isolate the solution. Sep 25, 2019 at 3:06
  • 1
    Maybe you have to ask a new question, if you need a solution for scrreprt. Additionally you did not say in your question, how subsections in appendix should be formatted and how the should be numbered.
    – esdd
    Sep 25, 2019 at 15:09
0

I found a solution that might be considered inelegant, but it works for me, and I can use the structure of the first code block shown in the question (where I can take advantages of the appendices packages and use the titletoc and title keys).

I simply looked at the KOMA-Script manual, found the default definition of \sectionlinesformat, and re-stated immediately (omitting the \@hangfrom) after beginning the appendices, and added a line break as follows.

\begin{appendices} 
\renewcommand{\sectionlinesformat}[4]{%
    \hskip #2#3\\#4%
}
\section{Something appended} \label{appa}
\end{appendices} 

I imagine it's better practice automatically include this command when beginning the appendices environment, perhaps xpatch is the way to go.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .