# How do I place a colored box in front of a \section*

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:

• 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
• Using titlesec package. – skpblack Jul 8 '17 at 9:17
• 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:

\documentclass{article}

\usepackage{lmodern, titlesec, xcolor}

\titleformat{name=\section,numberless}
{\normalfont\Large\bfseries}
{\color{yellow}\rule{1em}{1em}}
{1em}
{}

\begin{document}


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