# Background Color for Section Title

I have seen many answers to this question, but all of them seem very complicated and I don't understand how they work at all (copy and pasting them into my code doesn't seem to work either).

I should also add that I'm completely new to this.

All I want is a simple code that takes the default section title in LaTeX

and fills it in to become something like

This is what I currently have:

\documentclass[11pt, oneside]{article}
\usepackage{geometry}
\geometry{a4paper}
\usepackage{graphicx}

\begin{document}

\section{Introduction}

\end{document}


Any help will be much appreciated!

• Look at the titlesec package.
– user194703
Aug 31, 2019 at 3:59
• – user194703
Aug 31, 2019 at 4:34
• Should it be for all section titles, or only occasionally? Aug 31, 2019 at 9:13
• For all section titles. Aug 31, 2019 at 9:14

Here is a very simple solution with titlesec:

\documentclass[11pt, oneside]{article}
\usepackage{fourier}
\usepackage{geometry}
\geometry{a4paper}
\usepackage{graphicx}
\usepackage[, x11names]{xcolor}

\usepackage{titlesec}

\titleformat{\section}{\LARGE}{\rlap{\color{Aquamarine1!92!Chartreuse1}\rule[-0.4cm]{\linewidth}{1.2cm}} \thesection}{1em}{}

\begin{document}

\section{Introduction}

\end{document}


• This doesn't work if the \secnumdepth is set to 0. Dec 1, 2019 at 23:33
• Of course, in this case \thesection in the code is meaningless. Anyway, even for unnumbered sections, it is easy to adapt the code to \titleformat{name=\section,numberless]{...}. Dec 2, 2019 at 0:04
• Thanks, that works. Since this is your answer, do you want to add an answer to this question which is almost the same, but for the unnumbered section. Dec 2, 2019 at 0:13
• I'll do it in a moment. Thanks! Dec 2, 2019 at 0:17
• @AlanMunn: Colouring the frame is more complex than I thought. I'll look at it tomorrow (it's very late here…). Feel free to post if you have a solution Dec 2, 2019 at 0:48