我使用以下代码来格式化报告中的章节和部分。
\documentclass[a4paper, 11pt]{report}
\usepackage{xcolor}
\definecolor{dtured}{RGB}{153,0,0}
\definecolor{dtugray}{RGB}{153,153,153}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\sffamily\huge\bfseries}
{\color{dtured}{\chaptertitlename\ \thechapter}}{20pt}{\Large}
\titleformat{\section}
{\normalfont\sffamily\Large\bfseries\color{dtugray}}
{\thesection}{1em}{}
\begin{document}
\chapter{This has formatting}
\chapter*{This has not}
\end{document}
我现在想让相同的风格应用到我在环境中制作的章节\chapter*
,可以吗?
答案1
您可以使用 格式化已加星标的章节\titleformat{name=\chapter,numberless}[display]{...}{...}
。当然,您必须更改以下示例,因为\thechapter
对于已加星标的章节来说,这样做毫无意义。
\documentclass[a4paper, 11pt]{report}
\usepackage{xcolor}
\definecolor{dtured}{RGB}{153,0,0}
\definecolor{dtugray}{RGB}{153,153,153}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\sffamily\huge\bfseries}
{\color{dtured}{\chaptertitlename\ \thechapter}}{20pt}{\Large}
\titleformat{\section}
{\normalfont\sffamily\Large\bfseries\color{dtugray}}
{\thesection}{1em}{}
\titleformat{name=\chapter,numberless}[display]
{\normalfont\sffamily\huge\bfseries}
{\color{dtured}{\chaptertitlename\ \thechapter}}{20pt}{\Large}
\begin{document}
\chapter{This has formatting}
\chapter*{This has not}
\end{document}
编辑:
\documentclass[a4paper, 11pt]{report}
\usepackage{xcolor}
\definecolor{dtured}{RGB}{153,0,0}
\definecolor{dtugray}{RGB}{153,153,153}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\sffamily\huge\bfseries}
{\color{dtured}{\chaptertitlename\ \thechapter}}{20pt}{\Large}
\titleformat{\section}
{\normalfont\sffamily\Large\bfseries\color{dtugray}}
{\thesection}{1em}{}
\titleformat{name=\chapter,numberless}[display]
{\color{dtured}\normalfont\sffamily\huge\bfseries}
{}{-25pt}{\huge}
\begin{document}
\chapter{This has formatting}
text
\chapter*{Forord}
\addcontentsline{toc}{chapter}{Forord}
text
\end{document}