代码
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\chapter{Foo bar}
\lipsum[1-2]
\begin{tcolorbox}[size=tight,oversize,
sharp corners,
breakable,
enhanced,
interior style={top color=green!30!white,bottom color=green!30!white},
colframe=blue,
colupper=black,
left=170pt,
right=170pt,
bottom=10pt,
top=10pt,
]
\lipsum[2-3]
\end{tcolorbox}
\lipsum[2]
\end{document}
给出了这个结果:
但我想要这个结果(这是 Photoshop!):
答案1
您可以将选项与和underlay
结合使用。 允许引用其他框架图片或在附加部分使用节点。避免在填充的矩形后面出现虚假线条。remember
frame hidden
remember
current page
overlay|underlay
frame hidden
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\chapter{Foo bar}
\lipsum[1-2]
\begin{tcolorbox}[oversize,
remember,
sharp corners,
breakable,
enhanced,
frame hidden,
underlay first={\fill[green!30!white] (frame.north-|current page.west) rectangle (current page.south east);},
underlay last={\fill[green!30!white] (current page.north west) rectangle (current page.east|-frame.south);},
colframe=blue,
colupper=black,
bottom=10pt,
top=10pt,
]
\lipsum[2-3]
\end{tcolorbox}
\lipsum[2]
\end{document}
更新:如何保留标题?
我不知道如何解决这个问题。据我所知,您希望稍后绘制的内容(彩色框)不会覆盖已打印在页面上的内容(页眉)。可能会tcolorbox
留下一些有关损坏框的信息,这些信息可用于了解在打印页眉之前必须在下一页添加一些背景。但我不知道如何使用它。也许后续问题会吸引比我更聪明的人的兴趣。
我能做的最好的事情,看起来很糟糕,就是利用tikzpagenodes
包裹的帮助在标题区域打一个洞。
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\usepackage{tikzpagenodes}
\begin{document}
\chapter{Foo bar}
\lipsum[1-2]
\begin{tcolorbox}[oversize,
remember,
sharp corners,
breakable,
enhanced,
frame hidden,
interior hidden,
underlay first={\fill[green!30!white] (frame.north-|current page.west)
rectangle (current page.south east);},
underlay last={\begin{scope}[even odd rule, fill=green!30!white]
\fill[clip] (current page.north west) rectangle
(current page.east|-frame.south)
(current page header area.north west) rectangle
(current page header area.south east);
\end{scope}
},
colframe=blue,
colupper=black,
bottom=10pt,
top=10pt,
]
\lipsum[2-3]
\end{tcolorbox}
\lipsum[2]
\end{document}
答案2
这里有一个可破坏盒子的解决方案,它有两个部分(第一部分和最后一部分),您可以使用overlay first
并overlay last
为每个部分添加图形代码
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\chapter{Foo bar}
\lipsum[1-2]
\begin{tcolorbox}[size=tight,oversize,
sharp corners,
breakable,
enhanced,
interior style={top color=green!30!white,bottom color=green!30!white},
colframe=blue,
colupper=black,
left=170pt,
right=170pt,
bottom=10pt,
top=10pt,
remember,
overlay first={\fill[green!30!white]
(frame.south east) rectangle (current page.south west)
;},
overlay last={
\fill[green!30!white]
(frame.north west) rectangle (current page.north east)
;}
]
\lipsum[2-3]
\end{tcolorbox}
\lipsum[2]
\end{document}
更新
可以用opacity
键显示标题并增加颜色程度
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{mybox}{size=tight,oversize,
sharp corners,
breakable,
enhanced,
interior style={color=green!30!white},
colframe=blue,
colupper=black,
left=170pt,
right=170pt,
bottom=10pt,
top=10pt,
remember,
overlay first={\fill[green!30!white]
(frame.south east) rectangle (current page.south west)
;},
overlay last={
\fill[green,opacity=0.3]
([yshift=0.5pt]frame.north west) rectangle (current page.north east)
;
}}
\begin{document}
\chapter{Foo bar}
\lipsum[1-2]
\begin{mybox}
\lipsum[2-3]
\end{mybox}
\lipsum[2]
\end{document}