2

Using tcolorbox for chapter headings I never had a problem, except when I changed to asymmetric layout. Usually tcolorbox's option spread sidewards works just fine in a chapter's heading (you can remove the asymmetric option from the code below and test).

But using asymmetric layout I seem to have to experiment to find some values that could be used to spread to the width. What is causing this behavior and why do I have to manually find some values?

tcolorbox default calculation:

chapter head

manual calculation:

chapter

\documentclass[open=any]{scrbook}

\usepackage[a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,%
    textheight=49\baselineskip,headheight=\baselineskip,asymmetric,showframe]{geometry}
\usepackage{scrlayer-scrpage}
\KOMAoptions{headwidth=textwithmarginpar:0mm:0mm,footwidth=textwithmarginpar:0mm:0mm,headsepline,automark}

\usepackage[skins]{tcolorbox}
\renewcommand\chapterlinesformat[3]{%
  \begin{tcolorbox}[enhanced jigsaw,colframe=blue,colback=blue,sharp corners=all,
        height=.275\paperheight,valign=bottom,coltext=white,move upwards*,
        if odd page={spread outwards,spread inwards}{spread outwards=-52mm,spread inwards=\dimexpr\marginparwidth+\marginparsep}]
        #2\raggedchapter#3%
  \end{tcolorbox}
}

\begin{document}
    \chapter{Let's do some chapters with even some very long titles to see the text width}
    \chapter{Let's do some chapters with even some very long titles to see the text width}
    \chapter{Let's do some chapters}
    \chapter{Let's do some chapters}
    \chapter{Let's do some chapters}
\end{document}
2

With the asymmetric option you have a oneside layout. So you should set toggle enlargement to none:

\documentclass[open=any]{scrbook}

\usepackage[a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,%
    textheight=49\baselineskip,headheight=\baselineskip,showframe,asymmetric]{geometry}

\usepackage{scrlayer-scrpage}
\KOMAoptions{headwidth=textwithmarginpar:0mm:0mm,
             footwidth=textwithmarginpar:0mm:0mm,headsepline,automark}

\usepackage[skins]{tcolorbox}
\renewcommand\chapterlinesformat[3]{%
  \begin{tcolorbox}[enhanced jigsaw,colframe=blue,colback=blue,sharp corners=all,
        height=.275\paperheight,valign=bottom,coltext=white,move upwards*,
        spread outwards,spread inwards,toggle enlargement=none
        ]
        #2\raggedchapter#3%
  \end{tcolorbox}
}

\begin{document}
    \chapter{Let's do some chapters with even some very long titles to see the text width}
    \chapter{Let's do some chapters with even some very long titles to see the text width}
    \chapter{Let's do some chapters}
    \chapter{Let's do some chapters}
    \chapter{Let's do some chapters}
\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.