![色付きのセクションタイトルは、titlesec の [leftmargin] オプションで失敗する](https://rvso.com/image/390761/%E8%89%B2%E4%BB%98%E3%81%8D%E3%81%AE%E3%82%BB%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB%E3%81%AF%E3%80%81titlesec%20%E3%81%AE%20%5Bleftmargin%5D%20%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%A7%E5%A4%B1%E6%95%97%E3%81%99%E3%82%8B.png)
セクションタイトルに色を付けたいのですが、\titleformat
パッケージからtitlesec
設定すれば問題ありません。
しかし、オプション引数を追加すると[leftmargin]
、タイトルテキストの色が変更されません。コードに何か問題がありますか?
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}
答え1
回避策: 2 番目と 4 番目の引数に colour コマンドを配置します。
\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}