[Tex/LaTex] Remove additional space before section in tcolorbox

sectioningtcolorbox

When I set the parbox option of a tcolorbox to false, every section, even the first one, is preceded with additional whitespace. Is there any way to tell tcolorbox to handle the first section (subsection, …) in the same way as the first section on a page is treated, that is without additional space? That is, the following two boxes should look the same independent of the parbox option.

\documentclass{article}

\usepackage[many]{tcolorbox}

\begin{document}

\begin{tcolorbox}[parbox=false]
\section{Test}
\end{tcolorbox}

\begin{tcolorbox}
\section{Test}
\end{tcolorbox}

\end{document}

Best Answer

It work as you want it if one removes the \noindent and \leavevmode (inserted by tcolorbox) from \@parboxrestore. But as I don't understand why tcolorbox tries so hard to switch to horizontal mode at the start of the box I don't know if this has unwanted side-effects:

\documentclass[]{article}

\usepackage[many]{tcolorbox}
\tcbuselibrary{breakable}
\makeatletter
\def\tcb@parbox@use@false{%
  \def\@parboxrestore{\linewidth\hsize\let\@parboxrestore=\tcb@parboxrestore}%
}
\makeatother
\begin{document}

\begin{tcolorbox}[parbox=false]
\section{Test}
abc\par cde
\end{tcolorbox}

\begin{tcolorbox}
\section{Test}
abc\par cde
\end{tcolorbox}

\end{document}
Related Question