# Allowing paragraph continuation after a tcolorbox

I am using tcolorboxes and sometimes want them to be part of a larger paragraph, that is I want the text after the tcolorbox not to be indented. However, both \noindent and \@afterheading show some deficiencies (see comments in MWE).

How can I prevent the indentation following a tcolorbox without these deficiencies? I also don't want to lose the nice spacing provided by default (i.e. by /tcb/beforeafter skip balanced).

\documentclass{article}

\usepackage{tcolorbox}

\makeatletter

% This leads to extra spacing before a heading.

% This leads to reduced spacing before a heading as well as
% not allowing new paragraphs after the environment.
% It also prevents page breaks, which I do not want.

\begin{document}

\section{Indentation after Boxes}
Here's a box followed by a heading.
\begin{tcolorbox}
This box is followed by a heading.
\end{tcolorbox}

Here's a box that is part of a paragraph
\begin{tcolorbox}
This box should not lead to indentation of the following line.
\end{tcolorbox}
and should not cause indentation in this line.

And here's a box at the end of its paragraph.
\begin{tcolorbox}
This box is followed by a new, indented paragraph.
\end{tcolorbox}

This is a new paragraph.

\end{document}


• Why not just add \noindent manually before the continued line, as in \end{tcolorbox} \noindent and should not cause indentation in this line.? This would be the normal way to address this. – Steven B. Segletes Oct 29 '20 at 12:24
• @StevenB.Segletes I guess I'm lazy. I'm writing quite a lengthy document with a lot of these boxes.. – schtandard Oct 29 '20 at 18:33
• Lazy? I resemble that remark! – Steven B. Segletes Oct 29 '20 at 19:23

Appending \@endparenv, which is used by every list environment, to /tcb/after seems to work.

Update: For breakable boxes, some experimental attempt is added.

\documentclass{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{hooks, breakable}

\makeatletter
\tcbset{
after app={%
\ifx\tcb@drawcolorbox\tcb@drawcolorbox@breakable
\else
% add only when not breakabel
\@endparenv
\fi
}
}

% for breakable
\appto\tcb@use@after@lastbox{\@endparenv\@doendpe}
\makeatother

\begin{document}
\section{Indentation after Boxes}
Here's a box followed by a heading.
\begin{tcolorbox}
This box is followed by a heading.
\end{tcolorbox}

Here's a box that is part of a paragraph
\begin{tcolorbox}[title=Unbreakable]
This box should not lead to indentation of the following line.
\end{tcolorbox}
and should not cause indentation in this line.

Here's a box that is part of a paragraph
\begin{tcolorbox}[title=Breakable but not broken, breakable]
This box should not lead to indentation of the following line.
\end{tcolorbox}
and should not cause indentation in this line.

Here's a box that is part of a paragraph
\begin{tcolorbox}[title=Breakable and broken, breakable]
\lipsum[1-2]
\end{tcolorbox}
and should not cause indentation in this line.

And here's a box at the end of its paragraph.
\begin{tcolorbox}
This box is followed by a new, indented paragraph.
\end{tcolorbox}

This is a new paragraph.

\end{document}


• Nice! Any idea how to extend this to breakable boxes? – schtandard Oct 29 '20 at 18:17
• @schtandard Answer updated. I don't have much confident on the support for breakable boxes, hence use with care and feedback is welcome. – muzimuzhi Z Oct 29 '20 at 18:58
• Great! Two notes after some more experimenting: (1) Appending \@endpetrue (instead of \endparenv) seems to be enough and avoids additional breakpoints. (2) Appending to the \end macro also seems to work well, both for breakable and unbreakable boxes. That is, after defining boxed using \newtcolorbox, saying \long\appto\endboxed{\@endpetrue} does the trick. – schtandard Oct 29 '20 at 20:21