[Tex/LaTex] page number in a diamond box

header-footerpage-numbering

I have the following code I need to put the page number at the top of the page resulted in a diamond box. I would be grateful for any help or if you can indicate to me the code to generate it.

enter image description here

There is something I forgot, the page number should be on the left for the even pages and on the right for the odd pages.

Best Answer

One option using the fancyhdr and tikzpagenodes packages:

\documentclass{book}
\usepackage[a6paper]{geometry}
\usepackage{fancyhdr}
\usepackage{tikzpagenodes}
\usetikzlibrary{shapes.geometric}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[OC]{\begin{tikzpicture}[remember picture,overlay]
\node[diamond,draw,font=\small\itshape] at (current page header area.south west) (dia) {\thepage};
\draw[double=white] (dia.east) -- (current page header area.south east);
\end{tikzpicture}}
\fancyhead[EC]{\begin{tikzpicture}[remember picture,overlay]
\node[diamond,draw,font=\small\itshape] at (current page header area.south east) (dia) {\thepage};
\draw[double=white] (dia.west) -- (current page header area.south west);
\end{tikzpicture}}
\fancyhead[OR]{\small\nouppercase\leftmark}
\fancyhead[EL]{\small\nouppercase\rightmark}

\begin{document}

\chapter{Test chapter}
\lipsum[2]
\section{Test section}
\lipsum[2]\lipsum[2]\lipsum[2]\lipsum[2]\lipsum[2]

\end{document}

enter image description here

If the horizontal rules are not to be of the same width:

\documentclass{book}
\usepackage[a6paper]{geometry}
\usepackage{fancyhdr}
\usepackage{tikzpagenodes}
\usetikzlibrary{shapes.geometric}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[OC]{\begin{tikzpicture}[remember picture,overlay]
\node[diamond,draw,font=\small\itshape] at (current page header area.south west) (dia) {\thepage};
\draw (dia.3) -- (current page header area.south east|-dia.3);
\draw (dia.357) -- ([xshift=-7pt]current page header area.south east|-dia.357);
\end{tikzpicture}}
\fancyhead[EC]{\begin{tikzpicture}[remember picture,overlay]
\node[diamond,draw,font=\small\itshape] at (current page header area.south east) (dia) {\thepage};
\draw (dia.177) -- (current page header area.south west|-dia.177);
\draw (dia.183) -- ([xshift=7pt]current page header area.south west|-dia.183);
\end{tikzpicture}}
\fancyhead[OR]{\small\nouppercase\leftmark}
\fancyhead[EL]{\small\nouppercase\rightmark}

\begin{document}

\chapter{Test chapter}
\lipsum[2]
\section{Test section}
\lipsum[2]\lipsum[2]\lipsum[2]\lipsum[2]\lipsum[2]

\end{document}

enter image description here

Related Question