我在格式化章节标题时遇到了麻烦。我使用包来完成此操作titlesec
。我的目标是将章节编号放在左侧,然后在章节名称上方添加一行。我使用以下最小工作示例实现了此目的。但我不知道如何在此代码中增加章节名称的大小?
\RequirePackage{filecontents}
\begin{filecontents*}{test1.tex}
\chapter{Chapter One}
Text123\\
Text123\\
Text123
\end{filecontents*}
\documentclass[a4paper, liststotoc, bibtotoc, 12pt, numbers=noenddot, twoside]{book}
\usepackage{fancyhdr}
\usepackage[explicit]{titlesec}
\newlength\chapnumb
\setlength\chapnumb{4cm}
\titleformat{\chapter}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\fontsize{100}{10}\selectfont\thechapter}%fontsize number
\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}
\include{test1}
\end{document}
非常感谢您的帮助!!
答案1
这是 Ivan 已经提出的建议,因此应该归功于他。
\RequirePackage{filecontents}
\begin{filecontents*}[overwrite]{test1.tex}
\chapter{Chapter One}
Text123\\
Text123\\
Text123
\chapter*{Chapter Two}
Text123\\
Text123\\
Text123
\end{filecontents*}
\documentclass[a4paper, liststotoc, bibtotoc, 12pt, numbers=noenddot, twoside]{book}
\usepackage{fancyhdr}
\usepackage[explicit]{titlesec}
\newlength\chapnumb
\setlength\chapnumb{4cm}
\titleformat{\chapter}[block]
{\normalfont\sffamily}{}{0pt}
{\parbox[b]{\chapnumb}{%
\fontsize{100}{10}\selectfont\thechapter}%fontsize number
\parbox[b]{\dimexpr\textwidth-\chapnumb\relax}{%
\raggedleft%
\hfill{\fontsize{50}{10}\selectfont #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{\fontsize{50}{10}\selectfont #1}\\ % <<<<<<<<<<<<<<<<<<
\rule{\dimexpr\textwidth-\chapnumb\relax}{0.4pt}}}
\begin{document}
\include{test1}
\end{document}