我正在尝试将 \S 部分置于文档和页眉的中心
我用
\usepackage{sectsty} \allsectionsfont{\centering}
\usepackage{titlesec}
\setcounter{tocdepth}{1}
\titleformat{\section}[hang]{\normalfont\Large\bfseries}{\S\ \thesection}{1em}{}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries}{\S\ \thesubsection}{1em}{}
我明白了
在页眉处
我的代码
\documentclass[12pt,a4paper,twoside,openany]{book}
\usepackage{fouriernc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[left=2cm,right=2 cm,top=2cm,bottom=2cm]{geometry}
\usepackage{enumitem}
\usepackage{tasks}
\usepackage{siunitx}
\usepackage{lipsum}
\usepackage{float}
\sisetup{output-decimal-marker={,}}
\newtheorem{ex}{}
\newenvironment{ex*}
{\renewcommand\theex{\thechapter.\arabic{ex}\rlap{$^*$}}\ex}
{\endex}
\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{\chaptermark}[1]%
{\markboth{{\it \chaptername\,\thechapter.\ #1}}{}}
\renewcommand{\sectionmark}[1]%
{\markright{\it \thesection.\ #1}}
\lhead[\fancyplain{}{\thepage}]%
{\fancyplain{}{\rightmark}}
\rhead[\fancyplain{}{\leftmark}]%
{\fancyplain{}{\thepage}}
\cfoot{}
\sloppy
\usepackage{sectsty} \allsectionsfont{\centering}
\usepackage{titlesec}
\setcounter{tocdepth}{1}
\titleformat{\section}[hang]{\normalfont\Large\bfseries}{\S\ \thesection}{1em}{}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries}{\S\ \thesubsection}{1em}{}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
,unicode,bookmarksnumbered
}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\begin{document}
\tableofcontents
\chapter{GEOMETRIC PROPERTIES OF CURVES OF THE SECOND ORDER}
\setcounter{section}{17}
\section{The Ellipse}
\lipsum[1-5]
\end{document}
如何将 \S 部分置于文档和页眉的中心?
答案1
不要同时加载sectsty
,titlesec
它们会互相冲突。
fancyhdr
如果您想要居中标题,请使用插槽告知C
。我还删除了笨拙且已弃用的\fancyplain
部分:该包现在具有\fancypagestyle
可以重新定义页面样式并且更易于使用的功能。
为了使章节标题居中,请添加\filcenter
到规范中\titleformat
。
我还添加了几个选项geometry
:headheight
是必要的,因为它fancyhdr
会警告您;heightrounded
也是必要的,以确保页面上的行数为整数。
\documentclass[12pt,a4paper,twoside,openany]{book}
\usepackage{fouriernc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[
left=2cm,
right=2cm,
top=2cm,
bottom=2cm,
heightrounded,% <---- IMPORTANT
headheight=14.5pt,% <---- as asked by fancyhdr
]{geometry}
\usepackage{enumitem}
\usepackage{tasks}
\usepackage{fancyhdr}
\usepackage{titlesec}
%\usepackage{float}
\usepackage{siunitx}
\usepackage{lipsum}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
unicode,
bookmarksnumbered,
}
\sisetup{output-decimal-marker={,}}
\newtheorem{ex}{}
\newenvironment{ex*}
{\renewcommand\theex{\thechapter.\arabic{ex}\rlap{$^*$}}\ex}
{\endex}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CO]{\itshape\nouppercase{\rightmark}}
\fancyhead[CE]{\itshape\nouppercase{\leftmark}}
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0pt}%
}
\renewcommand{\chaptermark}[1]{\markboth{{\itshape Ch.\ \thechapter.\ #1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\itshape \S\ \thesection.\ #1}}
\titleformat{\section}[hang]
{\normalfont\Large\bfseries\filcenter}
{\S\ \thesection}
{1em}
{}
\titleformat{\subsection}[hang]
{\normalfont\large\bfseries\filcenter}
{\S\ \thesubsection}
{1em}
{}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\begin{document}
\tableofcontents
\chapter{GEOMETRIC PROPERTIES OF CURVES OF THE SECOND ORDER}
\setcounter{section}{17}
\section{The Ellipse}
\lipsum[1-20]
\end{document}