6

Why \vfill does not work inside tcolorbox? Here is my MuWE (Minimal unWorking Example)

\documentclass[]{scrartcl}
\usepackage[many]{tcolorbox}
    \newtcolorbox{bilety}
    {   enhanced,
        space to upper,
        height=5cm,
        %borderline={0.3mm}{0mm}{black!75, dashed},
        segmentation style={black, solid, opacity=0, line width=0pt},
        colback =  black!5!white,
        colframe = black!15!white,
        sharpish corners,
    }

\begin{document}

        \begin{bilety}
             some text
             \vfill
             some other text
        \end{bilety}

\end{document}

-------------------------PDF output is----------------------

enter image description here

But \vskip does!

    \begin{bilety}
         some text
         \vskip 3cm
         some other text
    \end{bilety}

-------------------------PDF output is----------------------

enter image description here

2
  • 1
    it is the vertical analogue of \mbox{a\hfill b} which does not stretch the box, boxing sets all glue at its natural size which is 0pt for \vfill although since a height is specified you might have hoped the package had used the height specification on the underlying minipage/vbox in which case it would have had an effect. Dec 31, 2014 at 0:16
  • The text inside the tcolorbox is boxed.
    – egreg
    Dec 31, 2014 at 0:19

1 Answer 1

9

In this case, it's a not a bug but a feature. The inner text box is decoupled from the fixed height setting for a number of reasons, e.g. lower box part support and breakability. Therefore, you cannot use \vfill, because the inner text box has no fixed height.

But, you can use a minipage with a fixed height inside the tcolorbox. You can put this minipage into the box setting options:

\documentclass[]{scrartcl}
\usepackage[many]{tcolorbox}

\newtcolorbox{bilety}
{   enhanced,
    space to upper,
    %height=5cm,
    segmentation style={black, solid, opacity=0, line width=0pt},
    colback =  black!5!white,
    colframe = black!15!white,
    sharpish corners,
    before upper={\begin{minipage}[t][4cm]{\linewidth}},
    after upper={\end{minipage}},
}

\begin{document}

  \begin{bilety}
    some text
    \par\vfill
    some other text
  \end{bilety}

\end{document}

Update (16-Nov-2018):

Alternatively, the option text fill can be used to automatically insert a minipage with adapted fixed height:

\documentclass[]{scrartcl}
\usepackage[many]{tcolorbox}

\newtcolorbox{bilety}
{   enhanced,
    %space to upper,
    height=5cm,
    %segmentation style={black, solid, opacity=0, line width=0pt},
    colback =  black!5!white,
    colframe = black!15!white,
    sharpish corners,
    text fill,
}

\begin{document}

  \begin{bilety}
    some text
    \par\vfill
    some other text
  \end{bilety}

\end{document}

enter image description here

1
  • 1
    For people interested, note that when the size is already given in the box, you can set directly the good size to the minipage by using: \begin{minipage}[t][\tcbtextheight]{1.0\linewidth}
    – tobiasBora
    Nov 13, 2018 at 11:14

You must log in to answer this question.

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