# Interference between ragged2e and tcolorbox: Additional spacing for centered bold text

When centering bold text in a tcolorbox using [halign upper=center], additional horizontal spacing occurs when the package ragged2e is loaded additionally.

I guess this is unintended behavior. – Is it possible to easily circumvent it?

\documentclass{scrartcl}

\usepackage{ragged2e}%    <- comment this for normal functioning
\usepackage{tcolorbox}

\begin{document}

\begin{center}
\bfseries centered bold text
\end{center}

\begin{tcolorbox}
\bfseries centered bold text
\end{tcolorbox}

\begin{tcolorbox}[halign upper=center]
\bfseries centered bold text
\end{tcolorbox}

\end{document}

• Jun 18, 2018 at 6:59
• Inserting \@raggedtwoe@spaceskipfalse\@raggedtwoe@everyselectfont as suggested there does not seem to help here. Jun 18, 2018 at 8:19

ragged2e hooks into the fontselection and sets there \spaceskip to 0pt. This overwrites the settings of tcolorbox. A \spaceskip of 0pt means that the normal interword space is used and in this context this space is stretched.

A local work-around would be to reset the \spaceskip to the value of tcolorbox:

\documentclass{scrartcl}

\usepackage{ragged2e}%    <- comment this for normal functioning
\usepackage{tcolorbox}

\begin{document}

\begin{tcolorbox}[halign upper=center]
\bfseries centered bold text
\end{tcolorbox}

\begin{tcolorbox}[halign upper=center]
\bfseries\spaceskip0.3333em\relax centered bold text
\end{tcolorbox}

\end{document}


A better solution would be probably if ragged2e would do nothing (as the documentation claims) if none of its commands is active:

\makeatletter

\renewcommand{\@raggedtwoe@everyselectfont}{%
\if@raggedtwoe@spaceskip
\ifdim\fontdimen\thr@@\font=\z@\relax
\spaceskip\z@
\else
\spaceskip\fontdimen\tw@\font
\fi
\else
%\spaceskip\z@ %removed
\fi
}

• Thanks for this comprehensive explanation and quick solution! I have notified the maintainer of ragged2e about your suggestion. Jun 19, 2018 at 6:36