如何更改章节编号颜色和章节名称颜色?
平均能量损失
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{lmodern}
\usepackage{lipsum}
\newlength\chapnumb
\setlength\chapnumb{4cm}
\titleformat{\chapter}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\fontsize{120}{110}\selectfont\thechapter}%
\parbox[b]{\dimexpr\textwidth-\chapnumb\relax}{%
\raggedleft%
\hfill{\LARGE#1}\ \rule{\dimexpr\textwidth-\chapnumb\relax}{0.4pt}}}
\titleformat{name=\chapter,numberless}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\mbox{}}%
\parbox[b]{\dimexpr\textwidth-\chapnumb\relax}{%
\raggedleft%
\hfill{\LARGE#1}\ \rule{\dimexpr\textwidth-\chapnumb\relax}{0.4pt}}}
\begin{document}
\chapter*{A Long Title for an Unnumbered Test Chapter}
\lipsum[4]
\chapter{Introduction}
\lipsum[4]
\end{document}
答案1
那么类似这样的情况怎么样:
\documentclass{book}
\usepackage[usenames]{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{lmodern}
\usepackage{lipsum}
\newlength\chapnumb
\setlength\chapnumb{4cm}
\titleformat{\chapter}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\fontsize{120}{110}\selectfont\textcolor{red}{\thechapter}}%
\parbox[b]{\dimexpr\textwidth-\chapnumb\relax}{%
\raggedleft%
\hfill{\textcolor{blue}{\LARGE#1}}\ \rule{\dimexpr\textwidth-\chapnumb\relax}{0.4pt}}}
\titleformat{name=\chapter,numberless}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\mbox{}}%
\parbox[b]{\dimexpr\textwidth-\chapnumb\relax}{%
\raggedleft%
\hfill{\textcolor{blue}{\LARGE#1}}\ \rule{\dimexpr\textwidth-\chapnumb\relax}{0.4pt}}}
\begin{document}
\chapter*{A Long Title for an Unnumbered Test Chapter}
\lipsum[4]
\chapter{Introduction}
\lipsum[4]
\end{document}