6

I think the picture explains my Problem very well:

enter image description here

The chapter enumeration on odd pages should behave the same as all other titles (e.g. subtitle on picture). I can't figure out why it is not working. Maybe someone has an idea?

Here's my code:

\documentclass[twoside]{scrreprt}
\usepackage{blindtext}

% Align titles to outer side
\renewcommand*{\raggedsection}{\ifthispageodd{\raggedleft}{\raggedright}}

% Push section enumeration outward
\renewcommand*{\sectionlinesformat}[4]{%
  \ifthispagewasodd
    #4\makebox[0pt][l]{\hskip\marginparsep #3}%
  \else
    \makebox[0pt][r]{#3\hskip\marginparsep}#4%
  \fi
}

% Push chapter enumeration outward 
\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
    \ifthispagewasodd
        #3\makebox[0pt][l]{\hskip\marginparsep #2}% % THE ERROR SHOULD BE HERE?
    \else
        \makebox[0pt][r]{#2\hskip\marginparsep}#3%
    \fi
}
\makeatother

\renewcommand*{\chapterformat}{\thechapter\autodot}
\renewcommand*{\sectionformat}{\thesection\autodot}
\renewcommand*{\subsectionformat}{\thesubsection\autodot}
\renewcommand*{\subsubsectionformat}{\thesubsubsection\autodot}

\begin{document}
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\end{document}
9

If I add \showtokens{#3} in the body of the redefinition of \chapterlinesformat, I get

> \interlinepenalty \@M Another Chapter\@@par .

and this explains why the number ends up in the next line: \par (the primitive one) is added at the end of the chapter title.

We have to remove the \@@par and reinsert it where it belongs.

\documentclass[twoside]{scrreprt}
\usepackage{blindtext}

% Align titles to outer side
\renewcommand*{\raggedsection}{\ifthispageodd{\raggedleft}{\raggedright}}

% Push section enumeration outward
\renewcommand*{\sectionlinesformat}[4]{%
  \ifthispagewasodd
    #4\makebox[0pt][l]{\hskip\marginparsep #3}%
  \else
    \makebox[0pt][r]{#3\hskip\marginparsep}#4%
  \fi
}

% Push chapter enumeration outward 
\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
    \ifthispagewasodd
        \remove@@par#3\makebox[0pt][l]{\hskip\marginparsep #2}\@@par
    \else
        \makebox[0pt][r]{#2\hskip\marginparsep}#3%
    \fi
}
\def\remove@@par#1\@@par{#1}
\makeatother

\renewcommand*{\chapterformat}{\thechapter\autodot}
\renewcommand*{\sectionformat}{\thesection\autodot}
\renewcommand*{\subsectionformat}{\thesubsection\autodot}
\renewcommand*{\subsubsectionformat}{\thesubsubsection\autodot}

\begin{document}
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.