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!

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

  • This doesn't work if the \secnumdepth is set to 0. – Alan Munn Dec 1 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]{...}. – Bernard Dec 2 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. – Alan Munn Dec 2 at 0:13
  • I'll do it in a moment. Thanks! – Bernard Dec 2 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 – Bernard Dec 2 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.