![tcolorbox 页面布局不对称的问题](https://linux22.com/image/358652/tcolorbox%20%E9%A1%B5%E9%9D%A2%E5%B8%83%E5%B1%80%E4%B8%8D%E5%AF%B9%E7%A7%B0%E7%9A%84%E9%97%AE%E9%A2%98.png)
使用 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}