3

I'm writing a longer text and redefined the Design of a Chapter start page using titlesec. For example

\documentclass[cleardoublepage=empty,fontsize=11pt,a4paper,twoside,DIV=calc]{scrbook}

\usepackage[no-math]{fontspec}
\usepackage{xunicode,xcolor} 
\usepackage{hyperref,titlesec,scalefnt}

\titleformat{\chapter}[display]%
    {\relax\huge\color{blue}}%
    {\Huge\raggedleft{\textcolor{blue!25}{\scalefont{4}\thechapter}}}{0pt}{}
\titlespacing{\chapter}{0pt}{\baselineskip}{\baselineskip}

\begin{document}
    \begin{mainmatter}
        \chapter{Eins}
    \end{mainmatter}
    \begin{backmatter}
        \chapter{Ein Beispiel}
    \end{backmatter}
\end{document}

Which sets the chapter number in light blue and huge to the right (see Chapter 1). But if i change into the backmatter to add an appendix chapter (which should be apendix A), the whole titlesec (from the second block) definition is lost. I would like to have A as the “appendix number” and set to the right, as the chapter number before (and of course “A An Example” to the toc).

How can i achieve, that the numbering is set to A (and shown) and that the titlesec-definition is not lost?

2
  • This should be useful (I hope you understand German): Incompatibilities between KOMA-Script and titlesec.
    – Speravir
    Commented Oct 26, 2012 at 17:46
  • Actually, i am german, so thanks for the links. I looked at some of the topics earlier, but i can't find a way to get the chapter number to the right with the koma script ”replacements“ for \titleformat
    – Ronny
    Commented Oct 26, 2012 at 18:07

2 Answers 2

2

\backmatter (which, BTW is -- like \frontmatter -- a switch, not an environment) will turn off sectioning numbering, including the numbering of appendices. Use \appendix instead of \backmatter.

\documentclass{scrbook}

\usepackage[no-math]{fontspec}
\usepackage{xunicode,xcolor} 
\usepackage{hyperref,titlesec,scalefnt}

\titleformat{\chapter}[display]%
    {\relax\huge\color{blue}}%
    {\Huge\raggedleft{\textcolor{blue!25}{\scalefont{4}\thechapter}}}{0pt}{}
\titlespacing{\chapter}{0pt}{\baselineskip}{\baselineskip}

\begin{document}

\mainmatter
\chapter{Eins}

\appendix
\chapter{Ein Beispiel}

\end{document}
3
  • Yah, okay, that's easier than mine :)
    – cgnieder
    Commented Oct 26, 2012 at 21:23
  • Actually, the frontmatter environment works fine, page numbers are roman, the PDF TOC is correct and the backmatter environment also does, what you mentioned. But i couldn't find any documentation of these environments, you're right. I wasn't aware, that backmatter turns numbering off. I thought Appendicies belong to the backmatter and was used to see them Numbered in roman numerals. So this solution is easier than i thought.
    – Ronny
    Commented Oct 27, 2012 at 6:17
  • And - actually - that also solved my second problem concerning the pagestyle, that was also changed in the backmatter and now just works fine (“A. An Example” as it should be).
    – Ronny
    Commented Oct 27, 2012 at 6:22
3

May I suggest not to use titlesec but to redefine \chapterformat and use \setkomafont{chapter}?

In order to get your requirements for the back matter we need \backmatter not to set \@mainmatterfalse but to reset the chapter counter instead.

Here is one way:

\documentclass[cleardoublepage=empty,fontsize=11pt,a4paper,twoside,DIV=calc]{scrbook}

\usepackage[no-math]{fontspec}
\usepackage{xunicode,xcolor} 
\usepackage{hyperref,scalefnt}
\usepackage{lipsum}% for dummy text

\makeatletter
% the chapter format:
\KOMAoption{chapterprefix}{true}
\renewcommand*\chapterformat{%
    \hbox to \linewidth{\hfill{\normalfont\Huge\color{blue!25}\scalefont{4}\thechapter}}%
  }
\setkomafont{chapter}{\normalfont\Huge\color{blue!25}}

% redefinition of \backmatter:
\renewcommand*\backmatter{%
  \if@openright\cleardoubleoddpage\else\clearpage\fi
  \setcounter{chapter}{0}%
  \renewcommand*\thechapter{\Alph{chapter}}%
  \@ifundefined{hypersetup}
    {}{\renewcommand*\theHchapter{\Alph{chapter}}}%
}
\makeatother

\begin{document}
\frontmatter
\tableofcontents

\mainmatter
\chapter{Eins}
\lipsum

\backmatter
\chapter{Ein Beispiel}
\lipsum

\end{document}
5
  • I tried to use \setkomafont but wasn't able to reproduce for example the \raggedleft - well you did :) . Though locksteps solution is easier and nicer.
    – Ronny
    Commented Oct 27, 2012 at 6:19
  • You could combine his and mine. This way you'd need one package less...
    – cgnieder
    Commented Oct 27, 2012 at 6:49
  • On the other hand, the code with titlesec is shorter, well nicer at least for the chapter number (and i use for example titletoc anyways). But maybe i'll give it a try.
    – Ronny
    Commented Oct 27, 2012 at 7:06
  • Well, "nicer" is a subjective attribute but if you need titletoc anyway you can quite as well use it, of course.
    – cgnieder
    Commented Oct 27, 2012 at 7:32
  • Of course, that's just subjective.
    – Ronny
    Commented Oct 27, 2012 at 8:28

You must log in to answer this question.

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