1

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

enter image description here

and fills it in to become something like

enter image description here

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!

1 Answers1

4

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}

enter image description here

Bernard
  • 271,350
  • This doesn't work if the \secnumdepth is set to 0. – Alan Munn Dec 01 '19 at 23:33
  • Of course, in this case \thesectionin the code is meaningless. Anyway, even for unnumbered sections, it is easy to adapt the code to \titleformat{name=\section,numberless]{...}. – Bernard Dec 02 '19 at 00: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. – Alan Munn Dec 02 '19 at 00:13
  • I'll do it in a moment. Thanks! – Bernard Dec 02 '19 at 00: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 – Bernard Dec 02 '19 at 00:48