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
  • Look at the titlesec package.
    – user194703
    Aug 31, 2019 at 3:59
  • 1
    e.g. tex.stackexchange.com/a/224147.
    – user194703
    Aug 31, 2019 at 4:34
  • Should it be for all section titles, or only occasionally?
    – Bernard
    Aug 31, 2019 at 9:13
  • For all section titles. Aug 31, 2019 at 9:14

1 Answer 1

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .