I'm using the MWE that Jesper Ipsen provided in the following question.

I intend to use colored boxes instead of section numbers. My idea was to implement it as shown in the following question.

Now the only thing that's left to do is to have an easy way of adding those boxes whenever I create a new section, as shown below:

\section*{Time Machines}

The idea is to have it appear like this:

enter image description here

  • Could you please add a MWE that shows what you've got so far? Which of the MWE's provided in the linked question do you use? – Skillmon Jul 8 '17 at 7:39
  • The one created by Jesper Ipsen. – user3776022 Jul 8 '17 at 7:43
  • 2
    Using titlesec package. – skpblack Jul 8 '17 at 9:17
  • 1
    An option could be to create a colored box with \newcommand\mybox[1][blue]{\textcolor{#1}{\rule{2ex}{2ex}}\hspace{0.5em}} with \usepackage{xcolor} package. In text: \section*{\mybox ABC} \section*{\mybox[red]Animals} – Bobyandbob Jul 8 '17 at 10:11
  • The linked answer of Jesper Ipsen is no MWE (not minimal). General information here. Detailed information for creating a minimal working example (MWE). Do you like to have always the same colored box or would you prefer changing colors for different sections? – Bobyandbob Jul 8 '17 at 10:34

As skpblack commented, package titlesec can be used for this:


\usepackage{lmodern, titlesec, xcolor}



\section{Another day in paradise}

A regular numbered section

\section*{Another night in paradise}

A starred section that has a coloured box


which gives

enter image description here

For fine tuning of spacing etc., refer to titlesec documentation.

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.