Position two tcolorboxes next to each other on the same line and adjust the distance between them?

tcolorbox

I have the following situation, where I have produced two boxes with text inside using the package tcolorbox:

\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}
\usepackage[most]{tcolorbox}

\begin{document}

\begin{tcolorbox}[colback=black!8!white,colframe=black, width=3cm]
\centering Males
\end{tcolorbox}
\begin{tcolorbox}[colback=black!8!white,colframe=black, width=3cm]
\centering Females
\end{tcolorbox}

\end{document}

However, with this code both boxes appear in different lines, and I would like to have them on the same line and to be able to adjust the distance between them using \hspace*{}.

How can this be done, preferably in a simple way?

Edit: the answers I received here are way more helpful, short and elegant than those provided in the related question that caused the close votes. For this reason, I don't believe the question should be closed.

Best Answer

You can use the before and after options:

\documentclass{article}
\usepackage{tcolorbox}

\begin{document}

\begin{tcolorbox}[colback=black!8,width=3cm,halign=center,after=\hspace{1cm}]
Males
\end{tcolorbox}
\begin{tcolorbox}[colback=black!8,width=3cm,halign=center,before=]
Females
\end{tcolorbox}

\end{document}

enter image description here

Related Question