# tcolorbox overflowing text when using parbox=false

I have the problem that when I add parbox=false to the options of tcolorbox, the text within the box is not breaking properly. Do you have an idea what might be the issue?

Here is the code:

\documentclass{tufte-book}
\usepackage[utf8]{inputenc}

\usepackage{blindtext}

\usepackage{amsmath}
\usepackage{cleveref}
\usepackage[most]{tcolorbox}
\usepackage[parfill]{parskip}

\newtheorem{thm}{Theorem}[chapter]

%--------Examples-------------
\newtcbtheorem
[use counter*=thm,number within=chapter,crefname={example}{examples},Crefname={Example}{Examples}]%
{ex}
{Example}
{%
before skip=10pt,after skip=10pt,
left=0.2cm,right=0.2cm,top=0cm,
toptitle=0.2cm,bottomtitle=0cm,
breakable,
toprule at break=0.2cm,
sharp corners,
colback=blue!10,
coltitle=black,
colframe=blue!10,
fonttitle=\bfseries,
parbox=false,
}% options
{ex}% prefix

\begin{document}

\begin{ex}{Test}{}
\Blindtext
\end{ex}

\end{document}


I am using the parskip package and want it to be applied to the contents of the tcolorbox too. That's why I want to set the parbox option to false.

With parbox=false:

Without parbox=false:

• Please add the missing parts to your code, so we can copy and run it. Jun 23 at 14:02
• @MS-SPO I changed the code so that you can copy/paste and run it :) Jun 23 at 15:32
• Seems to be related to the default ragged text setting in tufte-book document class. Jun 23 at 19:32
• @muzimuzhiZ thank you for your pointer! interestingly, adding the option halign=flush left (so \raggedright to every box) fixes things Jun 24 at 5:15

By using parbox=false, a customized \@parboxrestore is used for that tcolorbox.

% default definition in latex2e kernel
% $latexdef -s \@arrayparboxrestore % latex.ltx, line 11974: \def\@arrayparboxrestore{% \let\if@nobreak\iffalse \let\if@noskipsec\iffalse \let\par\@@par \let\-\@dischyph \let\'\@acci\let\\@accii\let\=\@acciii \parindent\z@ \parskip\z@skip \everypar{}% \linewidth\hsize \@totalleftmargin\z@ \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip \parfillskip\@flushglue \lineskip\normallineskip \lineskiplimit\normallineskiplimit \baselineskip\normalbaselineskip \sloppy} % customized one % tcolorbox.sty \def\tcb@parbox@false@settings{% \linewidth\hsize% \@totalleftmargin\z@% \leftskip\z@skip% \rightskip\z@skip% \@rightskip\z@skip% } \def\tcb@parbox@use@false{% \def\@parboxrestore{% \tcb@parbox@false@settings% \let\@parboxrestore=\tcb@parboxrestore% }% }  Among all those differences, the one relevant to OP's case is \sloppy (and the ragged text setting introduced by tutfe-book class), which is defined as %$ latexdef -s \sloppy
% latex.ltx, line 13894:
\DeclareRobustCommand\sloppy{%
\tolerance 9999%
\emergencystretch 3em%
\hfuzz .5\p@
\vfuzz\hfuzz}


Hence inserting \sopply is a direct solution. For better result and since tutfe-book class has loaded and configured ragged2e package, \justifying would help.

As for where to pass these commands, the best choice is some halign=<arbitrary alignment code> option which is not yet supported by tcolorbox. As a workaround, you can put them in font options like fontupper and fontlower.

\documentclass{tufte-book}
\usepackage{lipsum}
\usepackage{tcolorbox}

\begin{document}
\newcommand\test[1]{
\begin{tcolorbox}[title=\texttt{\detokenize{#1}}, #1]
\lipsum[2][1-6]
\end{tcolorbox}
}

Base case
\test{parbox=true}
\test{parbox=false}

Simulate \verb|parbox=true|
\test{parbox=false, fontupper=\sloppy}

Try better
\test{parbox=false, fontupper=\justifying}
\end{document}
`

• great answer, thank you! 2 hours ago