6

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}
7

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}

enter image description here

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. – FlorianL Jun 19 '18 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.