1

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 08 '17 at 07:39
  • The one created by Jesper Ipsen. – user3776022 Jul 08 '17 at 07:43
  • 2
    Using titlesec package. – skpblack Jul 08 '17 at 09: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 08 '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 08 '17 at 10:34
  • My mistake. I need to be able to change the colors depending on the section level, but the color of the section need to remain the same throughout the entire document. Like how subsection 1.1 and 2.1 are the same color because of how they're both subsection X.1. – user3776022 Jul 08 '17 at 10:52

1 Answers1

3

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}

\section{Another day in paradise}

A regular numbered section

\section*{Another night in paradise}

A starred section that has a coloured box

\end{document}

which gives

enter image description here

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