1

I want to create a box using the tcolorbox package that almost takes up an entire page and here's my MWE of a document that I compiled using LuaLaTeX in a scrbook class.

% !TeX program = lualatex

% DOCUMENT CLASS
\documentclass[%
% draft,
twoside,
headings=openany, % parts/chapters start on any page whether it's odd or even
DIV=15, % division factor
BCOR=12.5mm, % binding correction
headsepline=1.5pt, % header line
footsepline=0.4pt, % footer line
numbers=noenddot, % no dots at the end of section numbering
]{scrbook} % 11pt, a4paper (default)
% ----------------------------------------------------
% PACKAGES
\usepackage[
automark,
% footheight=18pt
]{scrlayer-scrpage} % KOMA-script package for headers, footers, pagestyles
\usepackage{setspace}\setdisplayskipstretch{} % For spacing
\usepackage[english]{babel}
\usepackage[babel]{microtype} % Microtypography
\usepackage{lipsum, blindtext} % For lorem ipsum dummy texts
\usepackage{mathtools, amsthm, amssymb} % Math packages
\usepackage{physics} % Physics package
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math} % Math fonts
\usepackage[theorems]{tcolorbox} % Colored boxes
\usepackage{empheq} % Emphasize equations
\usepackage{xcolor} % For colors
\usepackage{xparse} % For document-level commands
\usepackage{xpatch} % For patching commands
\usepackage{etoolbox} % e-TeX toolbox for classes and packages
\usepackage[
hidelinks
]{hyperref} % Hyperlinks and references
\usepackage[capitalise, nameinlink]{cleveref} % Clever cross-referencing features
\usepackage{showframe} % For page layout diagrams
% ----------------------------------------------------
% LAYOUT
  % Headers and footers
\renewcommand{\chaptermarkformat}{\chapapp~\thechapter.\enskip} % Add period after chapter number in header
\automark[section]{chapter} % LE and RO headers
\addtokomafont{pagenumber}{\normalsize\bfseries}
\ifoot*{} % inner footer
\cfoot*{\pagemark} % central footer
\ofoot*{} % outer footer
  % Part and chapter pagestyles
\renewcommand*{\partpagestyle}{empty}
\renewcommand*{\chapterpagestyle}{plain}
  % Section numbering
\setcounter{secnumdepth}{\subsectionnumdepth}
  % Section headings
% Font sizes
\setkomafont{part}{\Huge}
\setkomafont{chapter}{\huge}
\setkomafont{section}{\LARGE}
\setkomafont{subsection}{\Large}
% Replace \autodot by a fixed dot for chapter headings
\xpretocmd\chapterformat
  {\def\autodot{.}}
  {}{\cfPatchFailed}
% Spacing
\renewcommand*{\chapterheadstartvskip}{\vspace*{0cm}}
\renewcommand*{\chapterheadendvskip}{\vspace*{\baselineskip}}
\RedeclareSectionCommands[
  beforeskip=-.5\baselineskip,
  afterskip=.5\baselineskip
]{section}
\RedeclareSectionCommands[
  beforeskip=-.5\baselineskip,
  afterskip=.25\baselineskip
]{subsection}
% ----------------------------------------------------
% MACROS
  % Disable the error from using \label with amsmath nested environments
\makeatletter
\def\label@in@display{\gdef\df@label}
\makeatother
  % \ifstringsequalTF and \stringcase
\ExplSyntaxOn
\NewExpandableDocumentCommand{\ifstringsequalTF}{mmmm}
 {
  \str_if_eq:eeTF { #1 } { #2 } { #3 } { #4 }
 }
\NewExpandableDocumentCommand{\stringcase}{mO{}m}
 {
  \str_case_e:nnF { #1 } { #3 } { #2 }
 }
\ExplSyntaxOff
  % Positive space 
\newcommand{\PositiveSpace}{}
\NewDocumentCommand{\PS}{r()}
{%
\renewcommand{\PositiveSpace}{#1}
\ifstringsequalTF{\PositiveSpace}{0.5}%
  {\quad}{}%
\ifstringsequalTF{\PositiveSpace}{1}%
  {\qquad}{}%
\ifstringsequalTF{\PositiveSpace}{1.5}%
  {\qquad\quad}{}%
\ifstringsequalTF{\PositiveSpace}{2}%
  {\qquad\qquad}{}%
\ifstringsequalTF{\PositiveSpace}{2.5}%
  {\qquad\qquad\quad}{}%
\ifstringsequalTF{\PositiveSpace}{3}%
  {\qquad\qquad\qquad}{}%
\ifstringsequalTF{\PositiveSpace}{3.5}%
  {\qquad\qquad\qquad\quad}{}%
\ifstringsequalTF{\PositiveSpace}{4}%
  {\qquad\qquad\qquad\qquad}{}%
\ifstringsequalTF{\PositiveSpace}{4.5}%
  {\qquad\qquad\qquad\qquad\quad}{}%
\ifstringsequalTF{\PositiveSpace}{5}%
  {\qquad\qquad\qquad\qquad\qquad}{}%
}
  % Negative space 
\newcommand{\minusquad}{\mkern-18mu}
\newcommand{\minusqquad}{\mkern-36mu}
\newcommand{\NegativeSpace}{}
\NewDocumentCommand{\NS}{r()}
{%
\renewcommand{\NegativeSpace}{#1}
\ifstringsequalTF{\NegativeSpace}{0.5}%
  {\minusquad}{}%
\ifstringsequalTF{\NegativeSpace}{1}%
  {\minusqquad}{}%
\ifstringsequalTF{\NegativeSpace}{1.5}%
  {\minusqquad\minusquad}{}%
\ifstringsequalTF{\NegativeSpace}{2}%
  {\minusqquad\minusqquad}{}%
\ifstringsequalTF{\NegativeSpace}{2.5}%
  {\minusqquad\minusqquad\minusquad}{}%
\ifstringsequalTF{\NegativeSpace}{3}%
  {\minusqquad\minusqquad\minusqquad}{}%
\ifstringsequalTF{\NegativeSpace}{3.5}%
  {\minusqquad\minusqquad\minusqquad\minusquad}{}%
\ifstringsequalTF{\NegativeSpace}{4}%
  {\minusqquad\minusqquad\minusqquad\minusqquad}{}%
\ifstringsequalTF{\NegativeSpace}{4.5}%
  {\minusqquad\minusqquad\minusqquad\minusqquad\minusquad}{}%
\ifstringsequalTF{\NegativeSpace}{5}%
  {\minusqquad\minusqquad\minusqquad\minusqquad\minusqquad}{}%
}
  % Resizeable \bullet symbol
\newcommand{\rbullet}[1][.75]{\mathbin{\vcenter{\hbox{\scalebox{#1}{$\bullet$}}}}}
  % amsthm theorem environments
\newtheoremstyle{dotlessplain}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\itshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\(\rbullet\) \bfseries} % HEADFONT
  { }         % HEADPUNCT
  {\newline} % HEADSPACE
  {\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}}
\theoremstyle{dotlessplain} % italic
\newtheorem{theorem}{Theorem}[chapter]
    % tcolorbox environments
\newtcolorbox{summary}[2][]{colback=black!5!white,
colframe=black,boxrule=1pt,arc=2mm,toptitle=3mm,bottomtitle=3mm,center title,title=\textbf{\Large% 
Summary #2},#1}
% ----------------------------------------------------
% DOCUMENT
\begin{document}
% Page 1
\onehalfspacing
\KOMAoptions{DIV=current}
\chapter{First Chapter}
\section{First Section}
\subsection{First Subsection}
\lipsum[1-5][1-79]
\pagebreak
% Page 2
\begin{summary}[boxsep=0pt,left=10pt,right=10pt,top=10pt,bottom=10pt]{of Chapter 1}
\(\rbullet\) \textbf{Properties of Addition and Multiplication}
\begin{align*}
    &\text{(Associative law for addition)} \PS(0.5) & a + (b + c) &= (a + b) + c. \tag{P1}  \\
    &\text{(Existence of an additive identity)} \PS(0.5) & a + 0 &= 0 + a = a. \tag{P2} \\
    &\text{(Existence of additive inverses)} \PS(0.5) & a + (-a) &= (-a) + a = 0. \tag{P3} \\
    &\text{(Commutative law for addition)} \PS(0.5) & a + b &= b + a. \tag{P4} \\
    &\text{(Associative law for multiplication)} \PS(0.5) & a \cdot (b \cdot c) &= (a \cdot b) \cdot c. \tag{P5} \\
    &\text{(Existence of a multiplicative identity)} \PS(0.5) & a \cdot 1 &= 1 \cdot a = a;\quad 1 \neq 0. \tag{P6} \\
    &\text{(Existence of multplicative inverses)} \PS(0.5) & a \cdot a^{-1} &= a^{-1} \cdot a = 1, \text{ for } a \neq 0.  \tag{P7} \\
    &\text{(Commutative law for multiplication)} \PS(0.5) & a \cdot b &= b \cdot a. \tag{P8} \\
    &\text{(Distributive law)} \PS(0.5) & a \cdot (b + c) &= a \cdot b + a \cdot c. \tag{P9}
\end{align*}
\vskip 2ex
\(\rbullet\) \textbf{Properties of Inequality and Closure}
\begin{gather*}
    \begin{flalign*}
        &\text{(Trichotomy law) }  \text{For every number } a, \text{one and only one of the following holds:} & \tag{P10}
    \end{flalign*}
    \\
    \begin{align*}
        &\text{(i) } a = 0, && \\
        &\text{(ii) } a \text{ is in the collection } P, && \\
        &\text{(iii) } -a \text{ is in the collection } P. &&
    \end{align*}
    \\[7pt]
    \begin{flalign*}
        &\text{(Closure under addition) If } a \text{ and } b \text{ are in } P, \text{then } a + b \text{ is in } P. & \tag{P11} \\[5pt]
        &\text{(Closure under multiplication) If } a \text{ and } b \text{ are in } P, \text{then } a \cdot b \text{ is in } P. & \tag{P12}
    \end{flalign*}
\end{gather*}
\vskip -3ex
\begin{align*}
    &\PS(0.5) a > b \PS(0.5)\text{ if }\PS(0.5)  a - b \text{ is in } P; \\
    &\PS(0.5) a < b \PS(0.5)\text{ if }\PS(0.5) b > a; \\
    &\PS(0.5) a \geq b \PS(0.5)\text{ if }\PS(0.5) a > b \text{ or } a = b; \\
    &\PS(0.5) a \leq b \PS(0.5)\text{ if }\PS(0.5) a < b \text{ or } a = b.
\end{align*}
\vskip 2ex
\(\rbullet\) \textbf{Definition of the Absolute Value}
\begin{equation*}
\abs{a} = \sqrt{a^2} =
    \begin{cases*}
        \phantom{-}a, & if \(a\geq 0\) \\
        -a, & if \(a\leq 0\).
    \end{cases*}
\end{equation*}
\vskip 3ex
\begin{theorem}[\href{https://en.wikipedia.org/wiki/Triangle_inequality}{The Triangle Inequality}] 
        For all numbers \(a\) and \(b\), we have
        \[\abs{a + b} \leq \abs{a} + \abs{b}.\]
    \end{theorem}
\end{summary}
\vspace{\fill}
\pagebreak
% Page 3
\chapter{Second Chapter}
\section{Second Section}
\subsection{Second Subsection}
\lipsum[1-5][1-79]
\end{document}

The result to my untrained eye seems to be just fine

Page 1 Page 2 Page 3

but what I don't understand is why LaTeX tells me there's an Underfull \vbox (badness ...)warning.

Warning

So again, my question is how can I reduce the badness to remove the warning for this case specifically?

I've been looking everywhere for solutions on how to reduce/remove the Underfull \vbox (badness ...) warnings given by LaTeX and some solutions suggest that I could simply suppress the warnings if I wanted to but I'm afraid it might affect the typography of the whole document so I've avoided doing that so far. Thank you.

11
  • 1
    It's only a warning, you can ignore it or add \raggedbottom to your preamble (with \raggedbottom you avoid additional space among paragraphs to fill the page.
    – CarLaTeX
    Nov 22, 2021 at 6:00
  • It seems to fix it. Are there any side effects to adding \raggedbottom? Also, if you don't mind could you please create an answer so I can accept it? Thanks! :D Nov 22, 2021 at 6:08
  • 1
    The side effect is that it does not fill the pages between the paragraphs but at the end. See my answer.
    – CarLaTeX
    Nov 22, 2021 at 6:46
  • not directly related to the question but the definitions of PositiveSpace and friends seem weirdly complicated. As far as I can tell you just want \newcommand{\PositiveSpace}[1]{\hspace{2\dimexpr1em\relax}} Nov 22, 2021 at 8:25
  • Why don't you use \newpage instead of \pagebreak? Nov 22, 2021 at 8:30

1 Answer 1

2

You may add \raggedbottom that avoids additional space among paragraphs to fill the page.

I'll show you the difference between using it or not using it in the following examples. To simplify, I don't use your MWE, but it's just to explain the concept.

This example does NOT use \raggedbottom:

\documentclass{book}
\usepackage{graphicx}
\usepackage{tcolorbox}
\usepackage{lipsum}
\begin{document}
\chapter{This is what happens \emph{without} \textbackslash \texttt{raggedbottom}}
Some text before the box.
Some text before the box.
Some text before the box.
Some text before the box.
\begin{tcolorbox}[title=My first box, colframe=red]
\lipsum[1]
\end{tcolorbox}
Some text after the box.
Some text after the box.
Some text after the box.
Some text after the box.
\begin{tcolorbox}[title=My second box, colframe=green]
\lipsum[1]
\end{tcolorbox}
\end{document}

The output is:

enter image description here

This is the same example WITH \raggedbottom:

\documentclass{book}
\usepackage{graphicx}
\usepackage{tcolorbox}
\usepackage{lipsum}
\raggedbottom
\begin{document}
\chapter{This is what happens \emph{with} \textbackslash \texttt{raggedbottom}}
Some text before the box.
Some text before the box.
Some text before the box.
Some text before the box.
\begin{tcolorbox}[title=My first box, colframe=red]
\lipsum[1]
\end{tcolorbox}
Some text after the box.
Some text after the box.
Some text after the box.
Some text after the box.
\begin{tcolorbox}[title=My second box, colframe=green]
\lipsum[1]
\end{tcolorbox}
\end{document}

The output is:

enter image description here

Choosing one or another is a matter of taste or depends on the typographic conventions you must follow.

2
  • Thank you so much! I ended up using your solution but since I want most of my document to be flushbottom I simply used \oneraggedpage to toggle raggedbottom locally whenever needed. Again, thanks and have a nice day! :) Nov 22, 2021 at 7:19
  • @FarrelAhmed You're welcome!
    – CarLaTeX
    Nov 22, 2021 at 7:28

You must log in to answer this question.

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