![彩色部分標題因 titlesec 的 [leftmargin] 選項而失敗](https://rvso.com/image/390761/%E5%BD%A9%E8%89%B2%E9%83%A8%E5%88%86%E6%A8%99%E9%A1%8C%E5%9B%A0%20titlesec%20%E7%9A%84%20%5Bleftmargin%5D%20%E9%81%B8%E9%A0%85%E8%80%8C%E5%A4%B1%E6%95%97.png)
我希望我的章節標題有顏色。我用\titleformat
包裝裡的titlesec
設定就可以了。
但是當我添加選項參數時[leftmargin]
,標題文字無法更改顏色。我的程式碼有問題嗎?
微量元素:
\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
解決方法:將顏色指令放在第二個和第四個參數。
\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}