如何使用 \pagestyle{fancy} 使页码显示在右侧并让章节标题显示在左侧?

如何使用 \pagestyle{fancy} 使页码显示在右侧并让章节标题显示在左侧?

MWE 的负责人:

\documentclass[12pt,a4paper,oneside]{book}
\usepackage[a4paper,width=150mm,top=30mm,bottom=30mm,bindingoffset=6mm]{geometry}
\usepackage[nottoc]{tocbibind}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{bm}
\usepackage{nccmath}
\usepackage{amsfonts, graphicx, verbatim, mathtools,amssymb, amsthm, mathrsfs,amsmath}
\usepackage{color}
\usepackage{array}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{rsfso}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{babel, arrows.meta, positioning, quotes}
\usepackage{parskip}
\usepackage{lipsum}
\usepackage{upgreek}
\usepackage{floatrow}
\usepackage{epstopdf}
\usepackage[capitalise]{cleveref}
\usepackage{siunitx}
\usepackage{tocloft}
\usepackage{listings}
\usepackage{booktabs}
\usepackage{nicematrix}
\usepackage{subcaption}
\usepackage{multicol}
\usepackage{geometry}
\usepackage{tabularray} 
\UseTblrLibrary{booktabs, siunitx}
\usepackage[thinc]{esdiff}
\usepackage{ae}
\usepackage [english]{babel}
\usepackage [autostyle, english = american]{csquotes}
\usepackage[style=numeric,maxbibnames=200,sortcites=true,backend=bibtex]{biblatex}
\allowdisplaybreaks

\usepackage{mwe}
\usepackage{undertilde}
\usepackage{dsfont}
\usepackage{lmodern}
\usepackage{ae}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{tocloft}

\begin{document}
\frontmatter
\newpage
\pagestyle{fancy}
\fancyhf{}
\fancyhead[EL]{\nouppercase\leftmark}
\fancyhead[OR]{\nouppercase\rightmark}
\fancyhead[ER,OL]{\thepage}
\mainmatter
\chapter{one}
\section{a}
\lipsum[1-20]
\section{b}
\lipsum[1-20]
\chapter{two}
\section{c}
\lipsum[1-20]
\end{document}

正如我们在页面顶部看到的,每个部分的标题在右侧,而页码在左侧。我们如何翻转它,以便部分标题在左侧,而页码在右侧?

答案1

这样做:

\documentclass[12pt,a4paper,oneside]{book}
    \usepackage[a4paper,width=150mm,top=30mm,bottom=30mm,bindingoffset=6mm]{geometry}
    \usepackage[nottoc]{tocbibind}
    \usepackage[utf8]{inputenc} 
    \usepackage[T1]{fontenc} 
    \usepackage{bm}
    \usepackage{nccmath}
    \usepackage{amsfonts, graphicx, verbatim, mathtools,amssymb, amsthm, mathrsfs,amsmath}
    \usepackage{color}
    \usepackage{array}
    \usepackage{setspace}
    \usepackage{fancyhdr}
    \usepackage{rsfso}
    \usepackage{enumitem}
    \usepackage{tikz}
    \usetikzlibrary{babel, arrows.meta, positioning, quotes}
    \usepackage{parskip}
    \usepackage{lipsum}
    \usepackage{upgreek}
    \usepackage{floatrow}
    \usepackage{epstopdf}
    \usepackage[capitalise]{cleveref}
    \usepackage{siunitx}
    \usepackage{tocloft}
    \usepackage{listings}
    \usepackage{booktabs}
    \usepackage{nicematrix}
    \usepackage{subcaption}
    \usepackage{multicol}
    \usepackage{geometry}
    \usepackage{tabularray} 
    \UseTblrLibrary{booktabs, siunitx}
    \usepackage[thinc]{esdiff}
    \usepackage{ae}
    \usepackage [english]{babel}
    \usepackage [autostyle, english = american]{csquotes}
    \usepackage[style=numeric,maxbibnames=200,sortcites=true,backend=bibtex]{biblatex}
    \allowdisplaybreaks
    
    \usepackage{mwe}
    \usepackage{undertilde}
    \usepackage{dsfont}
    \usepackage{lmodern}
    \usepackage{ae}
    \usepackage{amsmath}
    \usepackage{xcolor}
    \usepackage{tocloft}
    
    \begin{document}
    \frontmatter
    \newpage
    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[ER]{\nouppercase\leftmark}
    \fancyhead[OL]{\nouppercase\rightmark}
    \fancyhead[EL,OR]{\thepage}
    \mainmatter
    \chapter{one}
    \section{a}
    \lipsum[1-20]
    \section{b}
    \lipsum[1-20]
    \chapter{two}
    \section{c}
    \lipsum[1-20]
    \end{document}

相关内容