我搜索了论坛并尝试了多种解决方案,但都无济于事。基本上,我希望一些章节标题和标题左对齐,而其他章节标题和标题居中。在我提供的代码片段(MWE)中,我使用 titletoc 和 titlesec 包来格式化章节标题和标题及其在目录中的外观。使用此代码,第一章是左对齐的(如我所愿),但第二章是完全对齐的,我希望居中。我所说的居中是指使用
\titleformat{\chapter}[block]
{\centering}
{\chaptertitlename\ \thechapter: }{12pt}{\LARGE}
定义章节格式。如何定义每个章节的标题/标题对齐方式?
梅威瑟:
\documentclass[12pt,letterpaper,titlepage]{report}
%%% Load packages %%%
\usepackage{titletoc}
\usepackage{titlesec}
%%% Modifications to default commands %%%
%% Add "Chapter #:" before numbered chapters in ToC
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{\bfseries}% <above-code>
{\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
{}% <numberless-entry-format>
{\hfill\contentspage}% <filler-page-format>
%% Format the title for chapters
\titleformat{\chapter}[block]
{\normalfont\LARGE\bfseries}
{\chaptertitlename\ \thechapter: }{12pt}{\LARGE}
\begin{document}
%%% Table of contents %%%
\tableofcontents %
\chapter{Introduction}
\begin{center}
\chapter{Maturation-disturbance cycles: endogenous spatiotemporal complexity in meta-ecosystems}
\end{center}
\end{document}
答案1
您可以\titleformat
在文档中使用多个命令。例如定义:
\newcommand\titlesflushleft
{\titleformat{\chapter}[block]%
{\normalfont\LARGE\bfseries}%
{\chaptertitlename\ \thechapter: }{12pt}{\LARGE}%
}
\newcommand\titlescentered
{\titleformat{\chapter}[block]%
{\filcenter\normalfont\LARGE\bfseries}%
{\chaptertitlename\ \thechapter: }{12pt}{\LARGE}%
}
然后你可以切换:
\begin{document}
\titlesflushleft
\tableofcontents
\chapter{Introduction}
\titlescentered
\chapter{Centered title}
\documentclass[12pt,letterpaper,titlepage]{report}
%%% Load packages %%%
\usepackage{titletoc}
\usepackage{titlesec}
%%% Modifications to default commands %%%
%% Add "Chapter #:" before numbered chapters in ToC
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{\bfseries}% <above-code>
{\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
{}% <numberless-entry-format>
{\hfill\contentspage}% <filler-page-format>
%% Format the title for chapters
\newcommand\titlesflushleft
{\titleformat{\chapter}[block]%
{\normalfont\LARGE\bfseries}%
{\chaptertitlename\ \thechapter: }{12pt}{\LARGE}%
}
\newcommand\titlescentered
{\titleformat{\chapter}[block]%
{\filcenter\normalfont\LARGE\bfseries}%
{\chaptertitlename\ \thechapter: }{12pt}{\LARGE}%
}
\begin{document}
\titlesflushleft
%%% Table of contents %%%
\tableofcontents %
\chapter{Introduction}
\titlescentered
\chapter{Maturation-disturbance cycles: endogenous spatiotemporal complexity in meta-ecosystems}
\end{document}