使用章节标题更改章节标题的大小,反之亦然

使用章节标题更改章节标题的大小,反之亦然

我想更改章节标题(即 blablabla)和章节标题(第 1 章)的大小,反之亦然。

\documentclass[10pt]{book}

\usepackage{titlesec}
\usepackage{fancyhdr}
\titleformat*{\section}{\large\bfseries}

\begin{document}

\chapter{blablabla}
\section{hello}
\end{document}

答案1

book使用\Huge为第一行,Chapter xy\huge使用 为章节标题。它用于宏\@makechapterhead。以下示例更改大小宏。

\documentclass[10pt]{book}

\usepackage{etoolbox}
\makeatletter
% Size of chapter titles changed from \Huge to \huge
\patchcmd\@makechapterhead{\Huge}{\huge}{}{%
  \errmessage{First patching \noexpand\@makechapterhead failed}%
}
\patchcmd\@makeschapterhead{\Huge}{\huge}{}{%
  \errmessage{Patching \noexpand\@makeschapterhead failed}%
}
% Size of first chapter head line of numbered chapters
% changed from \huge to \Huge
\patchcmd\@makechapterhead{\huge}{\Huge}{}{%
  \errmessage{Second patching \noexpand\@makechapterhead failed}%
}
\makeatother

\begin{document}

\chapter{blablabla}
\section{hello}
\end{document}

结果

答案2

下面我定义\swapHugehuge和,\revertHugehuge交换重新定义的\Huge和的定义:\huge\chapter

在此处输入图片描述

\documentclass{book}

\usepackage{xparse}

% Store original \huge and \Huge definitions
\let\oldHuge\Huge\let\oldhuge\huge
\let\oldchapter\chapter% Store original \chapter

% Define swapping/reverting mechanism
\newcommand{\swapHugehuge}{\let\huge\oldHuge\let\Huge\oldhuge}
\newcommand{\revertHugehuge}{\let\huge\oldhuge\let\Huge\oldHuge}
\RenewDocumentCommand{\chapter}{s o m}{%
  \swapHugehuge
  \IfBooleanTF{#1}
    {\oldchapter*{#3}}% \chapter*{..}
    {\IfValueTF{#2}
       {\oldchapter[#2]{#3}}% \chapter[.]{..}
       {\oldchapter{#3}}% \chapter{..}
    }%
  \revertHugehuge
}

\begin{document}

\chapter{A chapter}
\section{A section}

\end{document}

相关内容