5

I tried disabling the automatic starting of a new paragraph after a tcblisting or tcolorbox environment (from the tcolorbox package) by using \tcbset{after={\par\noindent}}. If I put this code in the main body of the document then I get the desired result:

Expected output

But if I put it in the preamble (where I think it ought to be) then I get something broken instead:

Unexpected output.

(The box seems to become part of the previous line.) This problem does not seem to occur with some other options, e.g. \tcbset{colback=yellow} gives the same result in both positions.

Is this behavior intended? If so, how can the option after={\par\noindent} be set globally in the preamble?

The used code for the unexpected output:

\documentclass[a4paper,10pt]{scrartcl}

\usepackage{tcolorbox}
\tcbset{after={\par\noindent}}

\begin{document}
%\tcbset{after={\par\noindent}}

Before the box.
\begin{tcolorbox}
  The box.
\end{tcolorbox}
After the box.

\end{document}

PS: I tried the above code with different compilers (LuaLaTeX, XeLaTeX and pdfLaTeX) on both my local machine and on Overleaf, and got the above situation each time.

6
  • I see no difference, and why should the after key change the behaviour before the tcolorbox? Aug 26 '19 at 19:39
  • @UlrikeFischer: The problem can be replicated on Overleaf, so I guess that it is not just my local machine. I don’t know why after would change the behavior before the tcolorbox, or if this really is what is happening. Aug 26 '19 at 20:05
  • overleaf uses an quite outdated texsystem. How current is your local system? Aug 26 '19 at 20:07
  • 2
    @UlrikeFischer I can reproduce the issue with a current TeX Live.
    – egreg
    Aug 26 '19 at 20:10
  • @egreg can you sent me a log? Aug 26 '19 at 20:14
7

By default tcolorbox uses the autoparskip. This option sets at the begin of the document the before and after keys to values sensible in dependance of the current value of \parskip.

If you are changing after in the preamble you are disabling autoparskip. In this case you have to set before yourself.

\documentclass[a4paper,10pt]{scrartcl}

\usepackage{tcolorbox}
\tcbset{before={\par\pagebreak[0]\smallskip\parindent=0pt},after={\par\noindent}}

\begin{document}


Before the box.
\begin{tcolorbox}
  The box.
\end{tcolorbox}
After the box.

\end{document}
4

In the preamble, use \AtBeginDocument{\tcbset{after={\par\noindent}}}.

\documentclass[a4paper,10pt]{scrartcl}

\usepackage{tcolorbox}
\AtBeginDocument{\tcbset{after={\par\noindent}}}

\begin{document}
%\tcbset{after={\par\noindent}}

Before the box.
\begin{tcolorbox}
  The box.
\end{tcolorbox}
After the box.

\end{document}

enter image description here

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.