2

The code

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

gives me this result:

enter image description here

but I want this result (it's Photoshop!):

enter image description here
Is there a way to do this?

2

You can use underlay options combined with remember and frame hidden. remember allows to make reference to other frame pictures or use current page node in overlay|underlay additions. frame hidden avoid spurious lines behind your filled rectangles.

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

enter image description here

Update: How to preserve header?

I don't know how to solve this problem. To my understanding you want that something which is drawn later (colored box) doesn't cover something which is already printed on your page (header). It's possible that tcolorbox leaves some information about a broken box which could be used to know that some background must be added to next page before the header is printed. But I don't know how to use it. May be follow up question attracts interest of more smart brains than mine.

The best I can do, which looks horrible, is making a hole for header area with tikzpagenodes package help.

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

enter image description here

| improve this answer | |
  • Thanks for your solution, but the header is gone! How can I bring it back? – Sisabe Jul 28 '15 at 6:14
  • @Sisabe I've updated the answer, but with a horrible solution. I think you'll need better help than mine. – Ignasi Jul 28 '15 at 8:04
1

Here a solution for breakable box with two parts (first and last), you can use overlay first and overlay last to add graphical code for each part

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

Update

You can show the header with opacity key and increase the color degree

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

enter image description here

| improve this answer | |
  • Thanks for your solution, but the header is gone! How can I bring it back? – Sisabe Jul 28 '15 at 6:14
  • Although opactiy let us see header, it's still covered. Compare it with footer in previous page. – Ignasi Jul 28 '15 at 8:22
  • @lgnasi This is the best of what I could get it. – Salim Bou Jul 28 '15 at 8:25
  • Or you can redefine header after the tclorbox? – Salim Bou Jul 28 '15 at 8:26
  • @salimbou: How to define the header after the tcolorbox? – Sisabe Jul 28 '15 at 15:49

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.