Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

LaTeX Change Default Section format

The following code demonstrates the default \section heading along with a custom \tcolorbox. I would like to alter the \section default to utilize the custom \tcolorbox function.

How can I change the default \section format to the customized \tcolorbox?

\documentclass[letter,10pt]{article}
\usepackage[utf8]{inputenc}

\RequirePackage[margin=.5in, top=.5in, bottom=1in]{geometry}
\raggedright\raggedbottom

\RequirePackage[most]{tcolorbox}

\newtcolorbox[auto counter]{SectionEnv}{
    enhanced,
    sharp corners=uphill,
    colback=gray!50,
    colframe=black,
    coltext=black,
    arc=3mm,
    boxrule=1mm,
    boxsep=1mm
}
\begin{document}

\section{Default Section Heading} % <-- default section heading

\begin{SectionEnv}

    \textbf{Desired Section Heading}

\end{SectionEnv}

\end{document}

Output of current code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Output from LaTeX

I reviewed this post on Changing Latex section numbering presentation however was unable to make use of the posted response.

>Solution :

You can use the same approach as in https://latex.org/forum/viewtopic.php?t=33217

\documentclass[letter,10pt]{article}
\usepackage[utf8]{inputenc}

\RequirePackage[margin=.5in, top=.5in, bottom=1in]{geometry}
\raggedright\raggedbottom

\RequirePackage[most]{tcolorbox}

\usepackage{xpatch}
\xpatchcmd{\section}{\normalfont\Large\bfseries}{\sectionbox}{}{\PatchFailed}

\newcommand*{\sectionbox}[1]{%
\begin{tcolorbox}
                 [
    enhanced,
    sharp corners=uphill,
    colback=gray!50,
    colframe=black,
    coltext=black,
    arc=3mm,
    boxrule=1mm,
    boxsep=1mm
                 ]
  #1
\end{tcolorbox} 
} %


\begin{document}

\section{Default Section Heading} % <-- default section heading



\end{document}

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading