1

In the following situation, when the outer left box is higher than the outer right box, i want to have the greatest possible height for the inner boxes (inside the raster of the outer right box).

\documentclass[11pt]{article}

\usepackage{tcolorbox}
\tcbuselibrary{skins}
\tcbuselibrary{raster}

\begin{document}

\tcbset{%
    outer left/.style={frame hidden, boxrule=0pt, boxsep=5pt, colback=yellow, halign=center, valign=center},
    outer right/.style={frame hidden, boxrule=0pt, boxsep=2pt, colback=orange, halign=center, valign=center},
    inner right/.style={boxsep=3pt, halign=center, valign=center}
}
\begin{tcbraster}[raster columns=2, raster equal height=rows, raster valign=center]
    \begin{tcolorbox}[outer left]
            w\\
            x\\
            y\\
            z
    \end{tcolorbox}
    %
    \begin{tcolorbox}[outer right]
        \begin{tcbraster}[raster columns=3]
            \begin{tcolorbox}[inner right]
                d
            \end{tcolorbox}
            %
            \begin{tcolorbox}[inner right]
                e
            \end{tcolorbox}
            %
            \begin{tcolorbox}[inner right]
                f
            \end{tcolorbox}
        \end{tcbraster}
    \end{tcolorbox}
\end{tcbraster}

\end{document}

enter image description here

I have come up with a hacky solution (far from being perfect) that seems to work after two successive compilations.

\documentclass[11pt]{article}

\usepackage{tcolorbox}
\tcbuselibrary{skins}
\tcbuselibrary{raster}

\begin{document}

\tcbset{%
    outer left/.style={frame hidden, boxrule=0pt, boxsep=5pt, colback=yellow, halign=center, valign=center},
    outer right/.style={frame hidden, boxrule=0pt, boxsep=2pt, colback=orange, halign=center, valign=center},
    inner right/.style={boxsep=3pt, halign=center, valign=center, ht}
}

\makeatletter
\begin{tcbraster}[raster columns=2, raster equal height=rows, raster valign=center]
    \begin{tcolorbox}[outer left]
            w\\
            x\\
            y\\
            z
    \end{tcolorbox}
    %
    \begin{tcolorbox}[outer right,
            code={%
                    \edef\tcb@ehgid{\kvtcb@raster@ehgid @\number\c@tcbrasterrow}%
                    \ifcsundef{tcb@ehg@height@\tcb@ehgid}%
                        {\tcbset{ht/.style={}}}%
                        {%
                                \tcbheightfromgroup\myht{\tcb@ehgid}%
                                \tcbdimto\myresult{\kvtcb@top@rule@stand+\kvtcb@bottom@rule@stand+\kvtcb@boxsep*2+\kvtcb@top+\kvtcb@bottom}%
                                \iftcb@hasTitle%
                                    \tcbdimto\myresult{\tcbtextheight+\ht\tcb@titlebox+\dp\tcb@titlebox+\kvtcb@title@rule+\kvtcb@boxsep*2+\kvtcb@toptitle+\kvtcb@bottomtitle}%
                                \fi%
                                \tcbdimto\myresult{\myht-\myresult}%
                                \tcbset{ht/.style={height=\myresult}}%
                        }%
            }
]
        \begin{tcbraster}[raster columns=3]
            \begin{tcolorbox}[inner right]
                d
            \end{tcolorbox}
            %
            \begin{tcolorbox}[inner right]
                e
            \end{tcolorbox}
            %
            \begin{tcolorbox}[inner right]
                f
            \end{tcolorbox}
        \end{tcbraster}
    \end{tcolorbox}
\end{tcbraster}
\makeatother

\end{document}

enter image description here But this solution requires me to delete the auxillary file and to recompile twice if any changes are made to the code (boxes content or settings like boxsep and so on).

Does anyone have a better solution? Thanks !

1 Answer 1

1

I think I have found a solution to my problem and it is based on the use of the space to key.

If it is tcolorbox included in the outer right box, we can use the add to natural height key.

On the other hand, if it is a raster, we will use the height key when the outer right box does not have its natural height (\myspace>0pt).

\documentclass[11pt]{article}

\usepackage{tcolorbox}
\tcbuselibrary{skins}
\tcbuselibrary{raster}


\begin{document}


\tcbset{%
    ht/.style={},
    outer left/.style={frame hidden, boxrule=0pt, boxsep=5pt, colback=yellow, halign=center, valign=center},
    outer right/.style={frame hidden, boxrule=0pt, boxsep=2pt, colback=orange, halign=center, valign=center},
    inner right/.style={boxsep=3pt, halign=center, valign=center, ht}
}

tcolorbox inside outer right box :

\begin{tcbraster}[raster columns=2, raster equal height=rows, raster  valign=center]
   \begin{tcolorbox}[outer left]
       w\\x\\y\\z
   \end{tcolorbox}
%
   \begin{tcolorbox}[outer right, space to=\myspace]
       \begin{tcolorbox}[inner right, add to natural height=\myspace]
         d
       \end{tcolorbox}
   \end{tcolorbox}
\end{tcbraster}

\begin{tcbraster}[raster columns=2, raster equal height=rows, raster valign=center]
   \begin{tcolorbox}[outer left]
       w
   \end{tcolorbox}
   %
   \begin{tcolorbox}[outer right, space to=\myspace]
       \begin{tcolorbox}[inner right, add to natural height=\myspace]
         d\\e\\f
       \end{tcolorbox}
   \end{tcolorbox}
\end{tcbraster}

tcbraster inside outer right box :

\begin{tcbraster}[raster columns=2, raster equal height=rows, raster valign=center]
   \begin{tcolorbox}[outer left]       
       w\\x\\y\\z
   \end{tcolorbox}
   %
   \begin{tcolorbox}[outer right, space to=\myspace]
       \ifdim\myspace>0pt\relax\tcbset{ht/.style={height=\myspace}}\fi%
       \begin{tcbraster}[raster columns=3]
           \begin{tcolorbox}[inner right]
               d
           \end{tcolorbox}
           %
           \begin{tcolorbox}[inner right]
               e
           \end{tcolorbox}
           %
           \begin{tcolorbox}[inner right]
               f
           \end{tcolorbox}
       \end{tcbraster}
   \end{tcolorbox}
\end{tcbraster}

\begin{tcbraster}[raster columns=2, raster equal height=rows, raster valign=center]
   \begin{tcolorbox}[outer left]
       w
   \end{tcolorbox}
   %
   \begin{tcolorbox}[outer right, space to=\myspace]
       \ifdim\myspace>0pt\relax\tcbset{ht/.style={height=\myspace}}\fi%
       \begin{tcbraster}[raster columns=3]
           \begin{tcolorbox}[inner right]
               d\\e\\f
           \end{tcolorbox}
           %
           \begin{tcolorbox}[inner right]
               f
           \end{tcolorbox}
           %
           \begin{tcolorbox}[inner right]
               g
           \end{tcolorbox}
       \end{tcbraster}
   \end{tcolorbox}
\end{tcbraster}

\end{document} 

enter image description here

You must log in to answer this question.

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