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

1 Answer 1

3

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

3
  • 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
    Commented Feb 18, 2019 at 1:28
  • One should take a look at the code for the leftmargin option.
    – Bernard
    Commented Feb 18, 2019 at 9:43
  • Oh, I think this is too hard for me.
    – lyl
    Commented Feb 18, 2019 at 11:47

You must log in to answer this question.

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