PROBLEM
So I'm finishing my tcolorbox styles for my writings, but I can't manage to center the text correctly if it is shorter than the \linewidth. One solution would be to add \centering every time, but it's not automatic, and I'm sure there's a better solution.
I also want that if the text is shorter than the \linewidth (as an example 3) center the box, and adapt de width of the box depending on the width of the text. Otherwise keep the max width the \linewidth and jump to a new line (with \centering).
In example 1, the centering is not build up correctly, instead of using halgin=center there should be like a text=centered (like \centering). And also, as it's shorter than the \linewidth, the width of the box should be adapted.
In example 3 the box should be centered, for this example I used hbox, which doesn't work if the text is larger than the \linewidth.
So is there any way to combine the example 3 when the text is short (with the box centered), and the example 1 when the text is larger (with correct center)?
MWE
The overlay= is just in case the box is way to big, and needs to jump to another page the borders are not rounded (to know that the box hasn't finished).
\documentclass[12pt]{report}
\usepackage{amsmath, amssymb}
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}
\newtcolorbox{box1}[1]{title={\centering\large#1}, fonttitle=\bfseries, toptitle=1.5mm, bottomtitle=1.5mm, enhanced, breakable, colback=gray, colframe=black, boxrule=1pt, arc=2mm, rounded corners, coltitle=white, coltext=white, halign=center,
overlay first={
\draw[line width=1pt, black] (frame.south west)--(frame.south east);},
overlay middle={
\draw[line width=1pt, black] (frame.south west)--(frame.south east);
\draw[line width=1pt, black] (frame.north west)--(frame.north east);},
overlay last={
\draw[line width=1pt, black] (frame.north west)--(frame.north east);;}
}
\newtcolorbox{box2}[1]{title={\centering\large#1}, fonttitle=\bfseries, toptitle=1.5mm, bottomtitle=1.5mm, enhanced, breakable, colback=gray, colframe=black, boxrule=1pt, arc=2mm, rounded corners, coltitle=white, coltext=white,
overlay first={
\draw[line width=1pt, black] (frame.south west)--(frame.south east);},
overlay middle={
\draw[line width=1pt, black] (frame.south west)--(frame.south east);
\draw[line width=1pt, black] (frame.north west)--(frame.north east);},
overlay last={
\draw[line width=1pt, black] (frame.north west)--(frame.north east);;}
}
\newtcolorbox{box3}[1]{title={\centering\large#1}, fonttitle=\bfseries, toptitle=1.5mm, bottomtitle=1.5mm, enhanced, breakable, colback=gray, colframe=black, boxrule=1pt, arc=2mm, rounded corners, coltitle=white, coltext=white, hbox,
overlay first={
\draw[line width=1pt, black] (frame.south west)--(frame.south east);},
overlay middle={
\draw[line width=1pt, black] (frame.south west)--(frame.south east);
\draw[line width=1pt, black] (frame.north west)--(frame.north east);},
overlay last={
\draw[line width=1pt, black] (frame.north west)--(frame.north east);;}
}
\begin{document}
\begin{box1}{Formula of $\sin(\theta)$}
$\forall\theta\in\mathbb{R}, \forall k\in\mathbb{Z},\sin(\theta+2\pi k)=\sin(\theta)$
\end{box1}
\begin{box2}{Formula of $\sin(\theta)$}
$\forall\theta\in\mathbb{R}, \forall k\in\mathbb{Z},\sin(\theta+2\pi k)=\sin(\theta)$
\end{box2}
\begin{box3}{Formula of $\sin(\theta)$}
$\forall\theta\in\mathbb{R}, \forall k\in\mathbb{Z},\sin(\theta+2\pi k)=\sin(\theta)$
\end{box3}
\end{document}


