I am using the fancyhdr package to customize my header and would like to display it with the section number, but without the section name, i.e. :

| Section ##                      Page #/total |
|                                              |

I am using the following code to custom the header:

\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
    \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]

Any ideas?




\begin{tikzpicture}[remember picture, overlay]
\draw[fill=blue,xshift=-.5\paperwidth,yshift=-.5cm] (0,0) rectangle
\node[anchor=north west,xshift=-.5\paperwidth,yshift=.5cm,text width=\paperwidth]
{\normalfont\huge\color{white}\quad{Section. \leftmark}};



\lipsum \lipsum \lipsum





and it works. :)

  • replace \leftmark with \thesection
    – touhami
    Jun 28, 2016 at 20:51
  • @touhami: That would do the trick, but when I do it, it gives the section number of the next section, i.e., for the first page of Section 5 it prints Section 6. Any idea why? Jun 28, 2016 at 20:59
  • where does Section 6 start? same page, next?
    – touhami
    Jun 28, 2016 at 21:07
  • 3
    Please, make the code into a compilable example. In any case, you need \renewcommand{\sectionmark}[1]{\markright{\thesection}}
    – egreg
    Jun 28, 2016 at 21:10
  • 1
    Please don't edit questions to include answers. This is not the way the site works. Edit your question to include an MWE. Then ask whoever helped you to write an answer which you can accept.
    – cfr
    Jun 30, 2016 at 2:08

2 Answers 2


If you want that the header contains just “Section 1” (or whatever the section number is), redefine \sectionmark:


(the word “Section” is already supplied by the other code). This way, \rightmark will contain the current section number.


You can redefine \sectionmark to suit your needs. Additionally, I've added what's needed for the Page ##/total (see How can I add "page # of ##" on my document?).

enter image description here


\fancyhead[R]{Page \thepage/\pageref{LastPage}}







You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .