5

I am trying to make a \begin{tcolorbox} which consumes the remainder of the page and other nested tcolorbox within, which consume the of remaining available area of the outter tcolorbox, Ie Nested boxes which consume the remainder of the page, to match a format for a microsoft word table that I am trying to mimick. However I think I must be comming up against some sort of fundamental problem or design feature in latex becasue I cant seem to find anything that allows me to set the bottom of a makebox/tcolorbox etc to the bottom of the page or size to the remaining page size. The code I am trying to use is shown below. (IE in the code below I dont want to use 6em, 30em etc). If possible can you also give me an explanation why this might be dificult to do in general.

I appreciate any help that anyone can give me, and would also to thank all those who have helped me along the way so far. I am sure I would have been lost or given up by now.

\begin{tcolorbox}[title=Outter tcolor Bo : I want to consume the whole page height,height=\textheight]
    Hello
    \begin{tcolorbox}[breakable,title=First Box: I want consume only required height,height=6em]
        I woud like this tcbbox to be a natural height and not inherit height from parent.
    \end{tcolorbox}
    \begin{tcolorbox}[breakable,title=Second Box: I want to consume the remaining height,height=30em]
        I woud like this tcbbox to consume the rest of the page
    \end{tcolorbox}
\end{tcolorbox}

enter image description here

1 Answer 1

6

It's a little bit tricky to achieve such a result, because the inner text content is assembled first and the outer box is constructed afterwards. My answer hacks into the internals of tcolorbox and saves the available space to macro written into the aux file. After compiling twice, the inner part 'knows' the available space. The saving macro is defined by the option save height.

\documentclass{article}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\makeatletter

\tcbset{%
  save height/.code={%
    \tcbset{breakable}%
    \providecommand{#1}{2cm}%
    \def\tcb@split@start{%
      \tcb@breakat@init%
      \tcb@comp@h@page%
      \def\tcb@ch{%
        \tcbset{height=\tcb@h@page}%
        \tcbdimto#1{#1+\tcb@h@page-\tcb@natheight}%
        \immediate\write\@auxout{\string\gdef\string#1{#1}}%
        \tcb@ch%
      }%
      \tcb@drawcolorbox@standalone%
    }%
  }%
}

\makeatother

\begin{document}

\tcbset{colback=yellow!10!white,colframe=red!50!black,fonttitle=\bfseries}

\begin{tcolorbox}[save height=\MyHeight,title=Outer tcolorbox: I want to consume the whole page height]
    Hello
    \begin{tcolorbox}[title=First Box: I want consume only required height,]
        I woud like this tcbbox to be a natural height and not inherit height from parent.
    \end{tcolorbox}
    \begin{tcolorbox}[title=Second Box: I want to consume the remaining height,height=\MyHeight]
        I woud like this tcbbox to consume the rest of the page
    \end{tcolorbox}
\end{tcolorbox}

\lipsum[1]

\begin{tcolorbox}[save height=\MyHeightTwo,title=Outer tcolorbox: I want to consume the whole page height]
    Hello
    \begin{tcolorbox}[title=First Box: I want consume only required height,]
        I woud like this tcbbox to be a natural height and not inherit height from parent.
    \end{tcolorbox}
    \begin{tcolorbox}[title=Second Box: I want to consume the remaining height,height=\MyHeightTwo]
        I woud like this tcbbox to consume the rest of the page
    \end{tcolorbox}
\end{tcolorbox}

\end{document}

enter image description here enter image description here

6
  • Thanks for the explanation Thomas, and the solution, I tried implementing your solution. But got the following error. (d:/Software/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)) geometry driver: auto-detecting geometry detected driver: pdftex ABD: EveryShipout initializing macros (d:/Software/texlive/texmf-dist/tex/latex/base/inputenc.sty) (d:/Software/texlive/texmf-dist/tex/latex/base/omscmr.fd) ! Undefined control sequence. \tcb@split@start ->\tcb@breakat@init \tcb@comp@h@page \def \tcb@ch {\tcbset ... l.134 \end{unitPlan}. Sep 19, 2014 at 3:57
  • I tried your code by itself, and could not get it to work stand alone. Getting the error Sep 19, 2014 at 5:29
  • Shown here ! Undefined control sequence. \tcb@split@start ->\tcb@breakat@init \tcb@comp@h@page \def \tcb@ch {\tcbset ... But this error disappeared when I remove the "save height = \MyHeight," and "height = \MyHeight", code snippets. I think this is just becasue your code is not called. I am not sure if the error is ocurring due to environmental differences, but I am using TeXworks and pdflatex. Thanks again for your help, I think I can adjust my document manually. Sep 19, 2014 at 5:39
  • @MichaelTMckeon I guess that's a version problem. This hack is working with tcolorbox version 3.12 (2014/07/29). After updating, it should work also on your system. Nevertheless, this hack is a hack using internals which might change in the future. But I'm thinking about to make an official feature for filling the rest of space for an outer box. Sep 19, 2014 at 6:19
  • 1
    @feculededentier Yes, it is the height fill option for unbreakable boxes. It fills the rest of the page with the outer box. For the inner box, there is no such option, because it is too specific. Aug 12, 2015 at 7:29

You must log in to answer this question.

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