我正在嘗試將 \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}