# How to add rectangle or other symbols before section name？

This is what I want.

MWE for test：

\documentclass[UTF8]{article}

\begin{document}
\section{section I}
\subsection{subsection I}
\section{section II}
\subsection{subsection II}
\end{document}


I would like to have a solution， that suitable for most documentclass.

• Can you make a minimal working example (MWE) that also shows which documetclass you are using? – user36296 May 25 '18 at 17:32
• @samcarter just normal article class, I would like to have a general solution, that suitable for most documentclass – sun0727 May 25 '18 at 18:01

You already added titlesec to your tags, so you could use this package. For example like this:

\documentclass[utf8]{article}
\usepackage{titlesec,xcolor}

\titleformat{\section}{\bfseries\Large}{\textcolor{orange}{\rule[-3pt]{5pt}{1em}}}{5pt}{}

\begin{document}
\section{section I}
\subsection{subsection I}
\section{section II}
\subsection{subsection II}
\end{document}


For example into stix (or fontawesome) fonts there are many nice symbols. I add a alternative MWE for your question.

\documentclass{article}
\usepackage{lipsum,xcolor}
\usepackage{stix}

\def\orr{\rlap{\protect\makebox[-2cm]{$\color{orange}\vrectangleblack$}}}

\begin{document}
\section{\orr section I}
\subsection{subsection I}
\section{\orr section II}
\subsection{subsection II}
\end{document}

• Why I have had a negative down? Can I have an explanation? – Sebastiano May 25 '18 at 21:07
• +1 from me - nice approach. – Dr. Manuel Kuehner May 25 '18 at 21:19
• @Dr.ManuelKuehner First of all, I thank you for your vote. With so much sincerity in this period I'm getting negative votes without understanding the cause. Thanks again. – Sebastiano May 25 '18 at 21:20
• I do not see any reason for a down vote. – Dr. Manuel Kuehner May 25 '18 at 21:22
• I think @samcarter means that your approach creates some negative effects on the PDF bookmarks (the [-2cm] bit). – Dr. Manuel Kuehner May 25 '18 at 21:28