1

Background

I'm using scrrept and titlesec (changing from titlesec to pure koma is on my todo list) any I've redefined \chapter to be a full page affair. The issue is when I'm using twosided.

Situation

My code includes \begin{minipage}[t]{8.2cm-\leftmargin}. However, when using twosided this means that only odd page's content is correctly positioned. I have tried changing this to the form \begin{minipage}[t]{8.2cm-\ifthispageodd{\leftmargin}{\rightmargin}}.

Issue

Unfortunately, this seems to have caused my compilation to hang (on 100% CPU usage though) at the final stage. See last log line below

Overfull \hbox (162.18062pt too wide) in paragraph at lines 156--156
| [] |
[12] (./demo.aux)

Thoughts so far

I'm guessing something like \expandafter is what I want (tried that before ifthispageodd, didn't work) but I don't know enough to get this to work.

Ideal Solution

Ideally, I'd actually use \newgeometry and fixed margins for the chapter pages to save me all of this accounting-for-changing-margins hassle. However, I couldn't get that to work without adding an extra page.

The Code

Relevant Section

\titleformat{\chapter}[display]
    {}
    {\titleBackground\thispagestyle{empty}}
    {4pt}
    {
        \begin{minipage}[t]{8.2cm-\ifthispageodd{\leftmargin}{\rightmargin}}

            \mbox{}\\
            \null\hfill\fontsize{6.5cm}{1ex}\selectfont{\ifbool{optionSolid}{\color{page}}{\color{primary}}\thechapter}
        \end{minipage}
        \hspace*{-5mm}
        \begin{minipage}[t]{\paperwidth-7cm-\ifthispageodd{\leftmargin}{\rightmargin}}
            \mbox{}\\
            \vspace*{-1.1cm}
            \begin{flushleft}
                \begin{spacing}{5}
                    \fontsize{1.7cm}{1em}
                    \fontseries{tx}
                    \selectfont
                    \ifbool{optionDark}{
                        \color{primaryVarient}
                    }{
                        \color{alternativePrimary}
                    }
    }[\end{spacing}\end{flushleft}\end{minipage}]

\titleformat{name=\chapter, numberless}[display]
    {}
    {\titleBackground\thispagestyle{empty}}
    {0pt}
    {
        \fontsize{2cm}{1em}
    }

}

MWE

\documentclass{scrreprt}

\usepackage{titlesec}
\usepackage{geometry}
\usepackage{ragged2e}
\usepackage{setspace}
\usepackage{xcolor}
\usepackage{etoolbox}

\newbool{optionDark}
\newbool{optionSolid}

\definecolor{page}{HTML}{FFFFFF} % white
\definecolor{text}{HTML}{000000} % black
\definecolor{primary}{HTML}{019875} % emerald
\definecolor{primaryVarient}{HTML}{1CBE77} % emerald mixed with lighter green
\definecolor{alternativePrimary}{HTML}{13293D} % blue

\setlength{\leftmargin}{1.5cm}
\setlength{\rightmargin}{2cm}

% \makeatletter
% Chapter format
\titleformat{\chapter}[display]
    {}
    {\thispagestyle{empty}}
    {4pt}
    {
        \begin{minipage}[t]{\dimexpr.2cm-\ifthispageodd{\leftmargin}{\rightmargin}\relax}
            \mbox{}\\
            \null\hfill\fontsize{6.5cm}{1ex}\selectfont{\ifbool{optionSolid}{\color{page}}{\color{primary}}\thechapter}
        \end{minipage}
        \hspace*{-5mm}
        \begin{minipage}[t]{\dimexpr\paperwidth-7cm-\ifthispageodd{\leftmargin}{\rightmargin}\relax}
            \mbox{}\\
            \vspace*{-1.1cm}
            \begin{flushleft}
                \begin{spacing}{5}
                    \fontsize{1.7cm}{1em}
                    \fontseries{tx}
                    \selectfont
                    \ifbool{optionDark}{
                        \color{primaryVarient}
                    }{
                        \color{alternativePrimary}
                    }
    }[\end{spacing}\end{flushleft}\end{minipage}]

\titleformat{name=\chapter, numberless}[display]
    {}
    {\thispagestyle{empty}}
    {0pt}
    {
        \fontsize{2cm}{1em}
    }

% \makeatother

\begin{document}

\newpage

\chapter{Demo Chapter}

\end{document}

Other Relevent Code

This is extracted from a class that I'm in the process of writing, which can be found here: https://github.com/tecosaur/bmc

  • You can't use \ifthispageodd there as it is not expandable. You need to use \ifthispageodd{\begin{minipage}{8.2cm-\leftmargin}}{\begin{minipage}{8.2cm-\rightmargin}}. – Skillmon Jan 28 at 1:22
  • Off-topic: Have you seen the warnings about using titlesec with scrreprt? We already have several questions about defining headings with KOMA-Script commands instead of titlesec. Please have a look at them. – Schweinebacke Jan 28 at 6:27
  • @Schweinebacke first paragraph of question: "changing from titlesec to pure koma is on my todo list" – Skillmon Jan 28 at 10:11
  • @Schweinebacke I'm in the process but I have some issues that need to be worked out – tecosaur Jan 28 at 20:31
  • 1
    AFAIK \leftmargin and \rightmargin are used for lists (and not for the page layout). – esdd Jan 29 at 10:44
2

As noted in the comments, \ifthispageodd is not expandable and can't be used inside of a \dimexpr therefore. The solution is to use \ifthispageodd outside of the \dimexpr:

\documentclass{scrreprt}

\usepackage{titlesec}
\usepackage{geometry}
\usepackage{ragged2e}
\usepackage{setspace}
\usepackage{xcolor}
\usepackage{etoolbox}

\newbool{optionDark}
\newbool{optionSolid}

\definecolor{page}{HTML}{FFFFFF} % white
\definecolor{text}{HTML}{000000} % black
\definecolor{primary}{HTML}{019875} % emerald
\definecolor{primaryVarient}{HTML}{1CBE77} % emerald mixed with lighter green
\definecolor{alternativePrimary}{HTML}{13293D} % blue

\setlength{\leftmargin}{1.5cm}
\setlength{\rightmargin}{2cm}

% \makeatletter
% Chapter format
\titleformat{\chapter}[display]
    {}
    {\thispagestyle{empty}}
    {4pt}
    {%
      \ifthispageodd
        {\begin{minipage}[t]{\dimexpr.2cm-\leftmargin\relax}}
        {\begin{minipage}[t]{\dimexpr.2cm-\rightmargin\relax}}
            \mbox{}\\
            \null\hfill\fontsize{6.5cm}{1ex}\selectfont{\ifbool{optionSolid}{\color{page}}{\color{primary}}\thechapter}
        \end{minipage}
        \hspace*{-5mm}
        \ifthispageodd
          {\begin{minipage}[t]{\dimexpr\paperwidth-7cm-\leftmargin\relax}}
          {\begin{minipage}[t]{\dimexpr\paperwidth-7cm-\rightmargin\relax}}
            \mbox{}\\
            \vspace*{-1.1cm}
            \begin{flushleft}
                \begin{spacing}{5}
                    \fontsize{1.7cm}{1em}
                    \fontseries{tx}
                    \selectfont
                    \ifbool{optionDark}{
                        \color{primaryVarient}
                    }{
                        \color{alternativePrimary}
                    }
    }[\end{spacing}\end{flushleft}\end{minipage}]

\titleformat{name=\chapter, numberless}[display]
    {}
    {\thispagestyle{empty}}
    {0pt}
    {%
        \fontsize{2cm}{1em}
    }

% \makeatother

\begin{document}

\chapter{Demo Chapter}

\end{document}

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.