T-F-S / tcolorbox

A LaTeX package to create highly customizable colored boxes.
http://www.ctan.org/pkg/tcolorbox
LaTeX Project Public License v1.3c
213 stars 15 forks source link

decreased space before list with parbox=false following a section heading #270

Open mbertucci47 opened 4 months ago

mbertucci47 commented 4 months ago

Sorry for adding to the list of issues with parbox=false, but I think with the fix for #262 a new issue has appeared. If a tcolorbox with parbox=false comes immediately after a section heading, then the space before a list that's preceded by text is decreased. Here's an example showing the issue:

\documentclass{article}
\usepackage{tcolorbox}

\begin{document}

\section{A section}

% too little space
\begin{tcolorbox}[parbox=false]
Some text
\begin{enumerate}
    \item First item 
    \item Second item 
\end{enumerate}
\end{tcolorbox}

% good
\begin{tcolorbox}[parbox=false]
Some text
\begin{enumerate}
    \item First item 
    \item Second item 
\end{enumerate}
\end{tcolorbox}

\subsection{A subsection}

% too little space
\begin{tcolorbox}[parbox=false]
Some text
\begin{enumerate}
    \item First item 
    \item Second item 
\end{enumerate}
\end{tcolorbox}

% good
\begin{tcolorbox}[parbox=false]
Some text
\begin{enumerate}
    \item First item 
    \item Second item 
\end{enumerate}
\end{tcolorbox}

% starting with a list is fine
\section{Another section}

\begin{tcolorbox}[parbox=false]
\begin{enumerate}
    \item First item 
    \item Second item 
\end{enumerate}
\end{tcolorbox}

\begin{tcolorbox}[parbox=false]
\begin{enumerate}
    \item First item 
    \item Second item 
\end{enumerate}
\end{tcolorbox}

\end{document}

document-1

There's no issue with boxes that start with a list.

muzimuzhi commented 4 months ago

Using overleaf (use \csname ver@tcolorbox.sty\endcsname to typeset version of tcolorbox),

muzimuzhi commented 4 months ago

I don't know why but prepending \let\if@nobreak\iffalse (which is the first assignment in \@arrayparboxrestore) to \tcb@parbox@false@settings seems to work.

Still need to find the "why part".

Example v2

```tex \documentclass{article} \usepackage[skins]{tcolorbox} \makeatletter \preto\tcb@parbox@false@settings{\let\if@nobreak\iffalse} \makeatother \newcommand\test[1][]{% \begin{tcolorbox}[#1, draft] Some text \begin{enumerate} \item First item \item Second item \end{enumerate} \end{tcolorbox} } \begin{document} LaTeX2e \fmtversion\par tcolorbox \csname ver@tcolorbox.sty\endcsname \section{parbox=false} \test[parbox=false] \test[parbox=false] \section{parbox=true} \test[parbox=true] \test[parbox=true] \end{document} ```

image

T-F-S commented 4 months ago

I don't know why but prepending \let\if@nobreak\iffalse (which is the first assignment in \@arrayparboxrestore) to \tcb@parbox@false@settings seems to work.

Still need to find the "why part".

I also wonder why the nobreak setting disturbs at this point.

Nevertheless, adding \let\if@nobreak\iffalse or \@nobreakfalse to \tcb@parbox@false@settings should do no harm and makes sense. If parbox=true is used, \if@nobreak equals \iffalse at begin of the tcolorbox interior of the MWE, but \iftrue for parbox=false.

So, I will add \@nobreakfalse to \tcb@parbox@false@settings.