I'd like to redefine \section
to produce something like the following: (requiring package tcolorbox
)
\begin{tcolorbox}
1. \hspace*{\fill} Title of the Section \hspace*{\fill}
\end{tcolorbox}
I assumed I could use the
titlesec
package to do so. I tried doing the following:
\titleformat{\section}[display]% It's not clear to me why, but any other format except [display] breaks!
{}{}{0em}%
{\begin{tcolorbox}\thesection.\hspace*{\fill}}% 'before' code.
[\hspace*{\fill}\end{tcolorbox}]% 'after' code.
The compiler accepts this, but not in the way that I expected it to. \section{Title of the Section}
produces the following:
I know that titlesec
does provide a boxed title option, but it is not in the format that I would like to use. In particular I would prefer for the label to also be in the box, and I would like the control over the box that tcolorbox
provides me.
I thought perhaps I could define the contents of this section title box in the titlesec
regime, then perhaps define \edef\oldsection\section
and redefine \section
as I like, but it's unclear to me how I might pass along the arguments that \section
takes.
TL;DR I'd like to put \section
titles inside a \tcolorbox
as in the first example, but it doesn't work.