4

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}
  • Do you really want to place a box around a section (subsection etc.)? – user31729 Jul 29 '14 at 6:39
  • If you omit parbox=false and use top=0pt,bottom=0pt as option instead, it should work – user31729 Jul 29 '14 at 6:44
  • I want to use parbox=false because I'd like to use the "normal" parskip behavior within the box. The content of the box is generated from markdown, therefore, I'd like to leave the content as is, if possible. – Jan Christiansen Jul 29 '14 at 6:59
4

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}
  • Thanks very much, I will check whether this change has undesired side-effects in my case. When I increase the parskip, the skip is also added to the top of the box. Is there a more elegant way to remove this skip than using a negative vspace at the top of the box? – Jan Christiansen Jul 29 '14 at 8:41

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.