I would like to set up a tcolorbox where the first paragraph is not indented, but subsequent paragraphs are indented.
I can accomplish this by passing an option like this to the box:
before upper=\setlength{\parindent}{1em}\noindent
The problem with this is that the \noindent causes TeX to enter horizontal mode. So if I start the box with something that should be in vertical mode (e.g., \section), extra vertical is inserted.
Is there a way I can automatically get the output I want without having to create two different kinds of boxes?
MWE
\documentclass{article}
\usepackage{tcolorbox}
\tcbset{mybox/.style={colback=white, colframe=blue, left=2mm, right=2mm,
fonttitle=\bfseries}, fontupper=\small,
before upper=\setlength{\parindent}{1em}\noindent}
\newtcolorbox{mybox}[1][]{mybox,#1}
\begin{document}
\begin{mybox}
The first paragraph should not have an indent.
Subsequent paragraphs should be indented.
\end{mybox}
\begin{mybox}
\section{Should not have gap above this heading}
\end{mybox}
\begin{mybox}[before upper=\setlength{\parindent}{1em}]
\section{Previous box should look like this}
\end{mybox}
\end{document}


centerenvironment disappears. e.g., add\begin{center}Text\end{center}to the end of the first box. – David Purton Aug 07 '19 at 14:56centerenvironment usually has space above and below right? With your code the space is still inserted below thecenterenvironment, but removed from above. This seems odd to me :) – David Purton Aug 07 '19 at 15:06\begin{center}Text\end{center}at the top of aminipage. – egreg Aug 07 '19 at 15:07minipageThere is still space above. I mean this output is weird (with your\everyparcode):\begin{mybox}Text\begin{center}Text\end{center}Text\end{mybox}– David Purton Aug 07 '19 at 15:12\everypar{…}it behaves as I would expect. – David Purton Aug 07 '19 at 15:13\begin{mybox}Text\begin{itemize}\item Text\end{itemize}Text\begin{center}Text\end{center}Text\end{mybox}Where theitemizespacing is wrong, but thecenterspacing is right. – David Purton Aug 07 '19 at 15:20top=0ptin the definition ofmybox, I get the same space withcenter,itemizeor simple text; more precisely, the first baseline is at the same position in all cases. – egreg Aug 07 '19 at 16:11