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}