tcolorbox 页面布局不对称的问题

tcolorbox 页面布局不对称的问题

使用 tcolorbox 制作章节标题时我从未遇到过问题,除非我更改为非对称布局。通常tcolorbox,选项spread sidewards在章节标题中工作正常(您可以从下面的代码中删除非对称选项并进行测试)。

但是使用非对称布局时,我似乎必须进行实验才能找到一些可用于扩展到宽度的值。是什么导致了这种行为?为什么我必须手动找到一些值?

tcolorbox默认计算:

章标题

手工计算:

章节

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

答案1

使用不对称选项,您将获得单侧布局。因此,您应该将切换放大设置为无:

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

在此处输入图片描述

相关内容