O título da seção colorida falha com a opção [leftmargin] do titlesec

O título da seção colorida falha com a opção [leftmargin] do titlesec

Quero o título da minha seção colorido. Está tudo bem quando eu uso \titleformato pacote titlesecpara configurá-lo.

Mas quando adiciono a opção argument [leftmargin], o texto do título não muda de cor. Há algo errado com meu código?

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}

insira a descrição da imagem aqui

Responder1

Uma solução alternativa: coloque o comando color no segundo e no quarto argumentos.

\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} 

insira a descrição da imagem aqui

informação relacionada