I like the nice yellow margins (top and bottom) and spacings from the yellow tcolorbox in "Subsection 2". Unfortunately I get this margins and spacing only directly after a \section
or \subsection
.
Problems:
a) Without a \section
or \subsection
in front of a tcolorbox the top margin is greater
b) I lose the white spacing between two tcolorboxes in some cases, see my examples. Especially the grey tcolorboxes have a white spacing between, but yellow ones do not.
How to get the same nice margins and spacings in any case? Of course there is no problem with additional white spacings after/ before a headings like \section
or \subsection
to respect the headings.
\documentclass[a4paper]{scrbook}
\usepackage{xparse}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,xparse}
\NewDocumentEnvironment{Material}{o}% recommend using xparse's arg-type o
{% begin-Befehle
\begin{tcolorbox}[%
parbox=false,% wenn dieser Befehl deaktiviert ist, dann sollte unten setlength{\parskip}{0.5\baselineskip plus2pt minus2pt} aktiviert sein.
enhanced jigsaw,%
breakable,% auskommentieren, wenn die Aufgaben in einer einzigen Box zusammenhängen sollen
grow to left by=2mm,%
left*=0mm,%
grow to right by=2mm,%
right*=0mm,%
boxrule=0pt,% keine Rahmenlinie
arc=0mm,% keinen Rundung in den Ecken
colback=gray!30,% Hintergrundfarbe im Body
%beforeafter skip balanced=0pt,% kein Abstand davor und dahinter
]%
\subsubsection{Material}
\IfValueTF{#1}
{\begin{itemize}[#1]}% optional #1 is given by user
{\begin{itemize}}% optional #1 has no value
}%
{% end-Befehle
\end{itemize}%
\end{tcolorbox}%
}%
\NewDocumentEnvironment{Content}{o}% recommend using xparse's arg-type o
{% begin-Befehle
\begin{tcolorbox}[%
parbox=false,% wenn dieser Befehl deaktiviert ist, dann sollte unten setlength{\parskip}{0.5\baselineskip plus2pt minus2pt} aktiviert sein.
enhanced jigsaw,%
breakable,% auskommentieren, wenn die Aufgaben in einer einzigen Box zusammenhängen sollen
grow to left by=2mm,%
left*=0mm,%
grow to right by=2mm,%
right*=0mm,%
boxrule=0pt,% keine Rahmenlinie
arc=0mm,% keinen Rundung in den Ecken
colback=yellow!30,% Hintergrundfarbe im Body
beforeafter skip balanced=0pt,% kein Abstand davor und dahinter
]%
\subsubsection{Content}
\IfValueTF{#1}
{\begin{itemize}[#1]}% optional #1 is given by user
{\begin{itemize}}% optional #1 has no value
}%
{% end-Befehle
\end{itemize}%
\end{tcolorbox}%
}%
\begin{document}
\begin{Content}
\item Content 1
\end{Content}
\begin{Content}
\item Content 1
\end{Content}
\begin{Material}
\item Material 1
\end{Material}
\begin{Material}
\item Material 1
\end{Material}
\subsection{Subsection 1}
\begin{Content}
\item Content 1
\end{Content}
\begin{Content}
\item Content 1
\end{Content}
\begin{Material}
\item Material 1
\end{Material}
\begin{Material}
\item Material 1
\end{Material}
\end{document}