1

I have used the following piece of code for colouring the text written in the section. The only problem which I am facing is that after adding this code my section is getting numbered which I don't want. Any suggestions?

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=0.4in]{geometry}
\usepackage{titling}
\usepackage{titlesec}
\usepackage{xcolor,lipsum}
\usepackage[most]{tcolorbox}

\titleformat{name=\section}[block]
{\sffamily\large}
{}
{0pt}
{\colorsection}


\newcommand{\colorsection}[1]{%
\colorbox{blue!20}{\parbox{\dimexpr\textwidth-2\fboxsep}{\thesection\ #1}}}

\begin{document}

   \section{This is the title}

\end{document}
2
  • It is easier to see the problem/solution if you provide a minimal working example which people can copy and compile directly, without having to guess what else might be contained in your document. However, does adding a * work? ie. \section*{This is the title} ?
    – Fintan
    Commented Aug 22, 2020 at 11:38
  • Sorry for the bad editing, I will edit the question properly. Yes i have tried using \section*{This is the title} and it doesnot work. Commented Aug 29, 2020 at 17:00

1 Answer 1

0

You're adding the section number with \thesection.

\newcommand{\colorsection}[1]{%
  \colorbox{blue!20}{%
    \parbox{\dimexpr\textwidth-2\fboxsep}{#1}%
  }%
}

enter image description here

1
  • Thanks a lot for this answer, it worked ! Was stuck on this from a long time ago, really thanks for helping me out ! Commented Aug 29, 2020 at 17:13

You must log in to answer this question.

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