1

I have noticed, when using mdframed and tcolorbox, that it is difficult to force the box to stretch to be exactly the height of the page.

Furthermore, the use of newpage and pagebreak does not work well with tcolorbox, although it does seem to work with mdframed.

How can I achieve a multi-page coloured box to hold content that is forced to be the height of the page?

1 Answer 1

1

Building on the answer here, I believe the easiest way to do it is to use tcolorbox with two smart custom commands:

\newcommand*{\fakebreak}{\par\vspace{\textheight minus \textheight}\pagebreak}
\newcommand*{\fakefill}{\par\vspace{\textheight minus \textheight}}
  • fakebreak allows you to fill the page and then induce a page break (although the next page will not have forced pageheight).
  • fakefill lets you force the box to have a height equal to that of the page (minus margins) without inducing a page break.

That gives you output like this, which is what you want, I think:

enter image description here

Unfortunately, if you are particular about using mdframed and not tcolorbox, I have not found a way to force that.


Code for the above:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[many]{tcolorbox}
\usepackage{tikz}

\begin{document}

\begin{tcolorbox}[%
parbox = false,
colback = white, colframe = black,
left = 0.5in, right = 0.5in, top = 0.5in, bottom = 0.5in,
height = \textheight,
sharp corners,
boxrule = 1pt,
breakable
]

\newcommand*{\fakebreak}{\par\vspace{\textheight minus \textheight}\pagebreak}
\newcommand*{\fakefill}{\par\vspace{\textheight minus \textheight}}

\begin{center}
\begin{tikzpicture}
\draw[rounded corners,thick, fill, fill opacity = 0.2] (-0.2,0) rectangle (2,2);
\end{tikzpicture}
\end{center}

\fakebreak


\begin{center}
    \begin{tikzpicture}
    \draw[rounded corners,thick, fill, fill opacity = 0.2] (-0.2,0) rectangle (2,2);
    \end{tikzpicture}
\end{center}

\fakefill

\end{tcolorbox}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .