# Section Number without name in header

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:

\usepackage{fancyhdr}
\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]
\node[anchor=west,xshift=.92\paperwidth,yshift=.025\paperheight,text width=\paperwidth]
\end{tikzpicture}
};
\end{tikzpicture}}


Any ideas?

Thanks

\documentclass{article}

\usepackage{tikz}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\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]
\end{tikzpicture}
}

\usepackage{lipsum}

\begin{document}
\section{blah}

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

\section{blahblah}

\lipsum

\lipsum

\end{document}


and it works. :)

• replace \leftmark with \thesection – touhami Jun 28 '16 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? – jorgehumberto Jun 28 '16 at 20:59
• where does Section 6 start? same page, next? – touhami Jun 28 '16 at 21:07
• Please, make the code into a compilable example. In any case, you need \renewcommand{\sectionmark}[1]{\markright{\thesection}} – egreg Jun 28 '16 at 21:10
• 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 '16 at 2:08

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

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


(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?).

\documentclass{article}

\usepackage{fancyhdr,lastpage,lipsum}
\pagestyle{fancy}
\fancyhf{}

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