0

I want my section title colored. It's all right when I use \titleformat from the package titlesec to set it.

But when I add the option argument [leftmargin], the title text fails to change color. Is something wrong with my code?

MWE:

\documentclass{article}
\usepackage{titlesec,xcolor}

\begin{document}
\titleformat{\section}
{\normalfont\bfseries\color{blue}}
{\thesection.}
{1em}
{}
\section{my colored section}

\titleformat{\section}[leftmargin]% only the optional argument "leftmargin" added
{\normalfont\bfseries\color{blue}}
{\thesection.}
{1em}
{}
\section{The Color Unchanged}

\end{document}

enter image description here

2

A work-around: put the colour command in the 2nd and 4th arguments.

\documentclass{article}
\usepackage{,xcolor, titlesec}

\begin{document}
\titleformat{\section}
{\normalfont\bfseries\color{blue}}
{\thesection.}
{1em}
{}
\section{my colored section}

\titleformat{\section}[leftmargin]% only the optional argument "leftmargin" added
{\normalfont\bfseries}
{\color{blue}\thesection.}
{1em}
{\color{blue}}
\section{The Color Unchanged}

\end{document} 

enter image description here

  • Yes, this can solve my problem. But I think this is only a temparory solution. Is this a problem of titlesec? Is there a final solution? – lyl Feb 18 at 1:28
  • One should take a look at the code for the leftmargin option. – Bernard Feb 18 at 9:43
  • Oh, I think this is too hard for me. – lyl Feb 18 at 11:47

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.