我添加了一些命令,以便将每个章节的标题居中,但这也会修改目录!我想将标题保留在章节开头的中心位置,但对于目录,我希望将其左对齐。
这是我的序言:
\documentclass[10pt,a4paper,twoside]{book}
\usepackage[paper = letterpaper, centering,
lmargin = 1.5in, rmargin = 1.5in,
tmargin = 1.5in, bmargin = 1.5in]{geometry}
\usepackage{fancyhdr}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\itshape\nouppercase{\rightmark}}
\fancyhead[RE]{\itshape\nouppercase{\leftmark}}
\renewcommand{\headrulewidth}{0.4pt}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{sectsty}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{mwe} % loads »blindtext« and »graphicx«
\usepackage{subfig}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{bm}
\usepackage{braket}
\usepackage{charter}
\usepackage{titlesec}
\titleformat{\chapter}[display]% NEW
{\fontfamily{ptm}\Large\bfseries\centering}{\chaptertitlename\ \thechapter}{20pt}{\huge}% NEW
\titlespacing*{\chapter}{0pt}{30pt}{20pt}% NEW
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.geometric, arrows}
\usepackage{cool}
\Style{DSymb={\mathrm d},DShorten=true,IntegrateDifferentialDSymb=\mathrm{d}}
\newtheorem{definizione}{Definizione}
\newtheorem{theorem}{Theorem}
\newtheorem{mydef}{Definition}
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
有什么建议么?
答案1
这是一个解决方案。使用\chapalign
带有的新命令\newcommand{\chapalign}{\centering}
\titleformat{\chapter}[display]% NEW
{\fontfamily{ptm}\Large\bfseries\chapalign}{\chaptertitlename\ \thechapter}{20pt}{\huge}% NEW
此命令在目录之前本地重新定义
\documentclass[10pt,a4paper,twoside]{book}
\usepackage{mwe}
\usepackage{titlesec}
\titleformat{\chapter}[display]% NEW
{\fontfamily{ptm}\Large\bfseries\chapalign}{\chaptertitlename\ \thechapter}{20pt}{\huge}% NEW
\titlespacing*{\chapter}{0pt}{30pt}{20pt}% NEW
\newcommand{\chapalign}{\centering}
\begin{document}
{\renewcommand{\chapalign}{}
\tableofcontents}
\blinddocument
\end{document}