某一页同时有section和subsection,页眉要怎么显示section的内容? 如图,这一页既有section和subsection,使用\rightmark,这一页的页眉是空的,只能在下一页显示subsection。我希望能做到: > 某页有section就显示section,没有section就显示subsection,我用\rightmark只能在没有section的页显示subsection ![](https://wenda.latexstudio.net/data/attach/200724/oaLuUovD.png) 代码如下: ``` \documentclass{ctexart} % FZSongS-Extended % FZSongS-Extended(SIP) % FZHei-B01 % FZKaiS-Extended % FZKaiS-Extended(SIP) % FZFangSong-Z02 \usepackage{geometry} \usepackage{titlesec} \usepackage{fancyhdr} \geometry{a4paper, scale=0.72} \spaceskip=1em %设置空格的距离 \xeCJKsetup{CJKspace=true, AutoFallBack=true, AutoFakeBold=2, CJKecglue={\hskip 0.2em}} \ctexset{section={format+=\raggedright}} % section居左 \setcounter{secnumdepth}{0} % 去掉编号 % \setCJKmainfont{FZSongS-Extended} % \setCJKsansfont{FZHei-B01} % \setCJKmonofont{FZFangSong-Z02} % 设置字体 \setCJKfamilyfont{zhsong}{FZSongS-Extended}[FallBack=FZSongS-Extended(SIP)] \setCJKfamilyfont{zhhei}{FZHei-B01}[FallBack=FZSongS-Extended(SIP)] \setCJKfamilyfont{zhkai}{FZKaiS-Extended}[FallBack=FZKaiS-Extended(SIP)] \setCJKfamilyfont{zhfs}{FZFangSong-Z02}[FallBack=FZSongS-Extended(SIP)] \renewcommand*{\songti}{\CJKfamily+{zhsong}} \renewcommand*{\heiti}{\CJKfamily+{zhhei}} \renewcommand*{\kaishu}{\CJKfamily+{zhkai}} \renewcommand*{\fangsong}{\CJKfamily+{zhfs}}{\relax} % 设置样式 \titleformat*{\section}{\songti} \titleformat*{\subsection}{\heiti} \titlespacing*{\section}{0pt}{0em}{0.5em} \titlespacing*{\subsection}{0pt}{0.5em}{0em} \newcommand*{\juan}[1]{\clearpage\noindent\LARGE\section{#1}\par} \newcommand*{\jnyuan}[1]{\noindent\Large\subsection{#1}\par} \newcommand*{\jnyi}[1]{\noindent\Large\heiti{#1}\par} \newcommand*{\zwyuan}[1]{\large\songti{#1}\par} \newcommand*{\zwyi}[1]{\kaishu{#1}\par} \newcommand*{\spyuan}[1]{\hangafter 0\hangindent 2em\fangsong{#1}\par} \newcommand*{\spyi}[1]{\hangafter 0\hangindent 2em\fangsong{#1}\par}{\relax} % 页眉页脚 \fancyhf{} % 清空当前设置 \renewcommand{\headrulewidth}{0.5pt} \pagestyle{fancy} \fancyhead[L]{\kaishu\thepage} \fancyhead[R]{\kaishu\rightmark} \usepackage{hyperref} \hypersetup{colorlinks=true, hidelinks, bookmarksopen=true, bookmarksnumbered=true, pdftitle=文白对照资治通鉴, pdfstartview=FitH} \begin{document} ```

1 回答1

0
你写的80%是废代码,这才是MWE,具体的意思去看 lshort-zh-cn 和刘海洋 ```tex \documentclass{article} \usepackage{fancyhdr} \fancyhf{} \pagestyle{fancy} \fancyhead[R]{\rightmark} \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}} \fancypagestyle{plain}{ \pagestyle{fancy} \fancyhead[R]{\leftmark} } \begin{document} \section{test1} \subsection{test2} \newpage \mbox{} \newpage \subsection{test3} \newpage \mbox{} \end{document} ```
  • 非常感谢! – 輪迴 2021-02-16 18:50 回复

你的回答

请登录后回答

你的回答将会帮助更多人,请务必认真回答问题。