标题中没有名称的章节编号

标题中没有名称的章节编号

我正在使用花式高清包来定制我的标题,并希望显示它与部分编号,但不显示部分名称,即:

 ______________________________________________
| Section ##                      Page #/total |
|                                              |

我正在使用以下代码来自定义标题:

\usepackage{fancyhdr}
\fancyhead[C]{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-.05\paperheight] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
    \draw[fill=MainColor] (0,0) rectangle
    (\paperwidth,.05\paperheight);;
    \node[anchor=west,xshift=.01\paperwidth,yshift=.025\paperheight,text width=\paperwidth]
    {\normalfont\huge\color{white}\quad{Section \leftmark}};
    \node[anchor=west,xshift=.92\paperwidth,yshift=.025\paperheight,text width=\paperwidth]
    {\normalfont\normalsize\bfseries\textcolor{white}{\thepage/\hypersetup{linkcolor=white}\pageref{LastPage}}};
    \end{tikzpicture}
};
 \end{tikzpicture}}

有任何想法吗?

谢谢

编辑: 添加 MWE

\documentclass{article}

\usepackage{tikz}
\usepackage{fancyhdr}
% HEADER %
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=blue,xshift=-.5\paperwidth,yshift=-.5cm] (0,0) rectangle
(1.1\paperwidth,1.5cm);;
\node[anchor=north west,xshift=-.5\paperwidth,yshift=.5cm,text width=\paperwidth]
{\normalfont\huge\color{white}\quad{Section. \leftmark}};
\end{tikzpicture}
}

\usepackage{lipsum}

\begin{document}
\section{blah}

\lipsum
\subsection{asdf}
\lipsum \lipsum \lipsum

    \section{blahblah}

    \lipsum

    \lipsum

\end{document}

并且它有效。:)

答案1

如果您希望标题仅包含“第 1 节”(或任何节号),请重新定义\sectionmark

\renewcommand{\sectionmark}[1]{\markright{\thesection}}

(“Section” 一词已由其他代码提供)。这样,\rightmark将包含当前部分编号。

答案2

您可以重新定义\sectionmark以满足您的需要。此外,我还添加了所需的内容Page ##/total(请参阅如何在我的文档中添加“第 # 页,共 ## 页”?)。

在此处输入图片描述

\documentclass{article}

\usepackage{fancyhdr,lastpage,lipsum}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Section~\leftmark}
\fancyhead[R]{Page \thepage/\pageref{LastPage}}

\makeatletter
\renewcommand{\sectionmark}[1]{\markboth{\ifnum\c@secnumdepth>\z@\thesection}{}}
\makeatother

\begin{document}

\section{blah}\lipsum

\subsection{asdf}\lipsum\lipsum\lipsum

\section{blahblah}\lipsum\lipsum

\end{document}

相关内容