I've been playing with the design of a letterhead class for our department. We want two pictures on the header, with a line under it; and the address on the footer, with a line over it. Here is a MWE that works OK:
mwe.cls:
% Class declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwe}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}
\ProcessOptions \relax
\LoadClass{letter}
% Packages
\RequirePackage{tikz}
\RequirePackage{graphicx}
\RequirePackage[utf8]{inputenc}
\RequirePackage[brazil]{babel}
\RequirePackage[a4paper,left=1.9cm,right=1.9cm,top=3.2cm,bottom=3.3cm,headheight=56pt,headsep=0.1in]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{xcolor}
% Colors
\definecolor{xLine}{rgb}{.58,.80,.87}
\definecolor{xAddr}{rgb}{.19,.52,.61}
% Change width and color of the lines under header and over footer
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\headrule}{\hbox to\headwidth{\color{xLine}\leaders\hrule height \headrulewidth\hfill}}
\renewcommand{\footrulewidth}{2pt}
\renewcommand{\footrule}{\hbox to\headwidth{\color{xLine}\leaders\hrule height \footrulewidth\hfill}}
\fancypagestyle{plain}{
\fancyhf{}
\lhead{\includegraphics[height=1.5cm]{logo1.png}\vspace{-3mm}}
\rhead{\includegraphics[height=1.5cm]{logo2.png}\vspace{-3mm}}
\fancyfoot[C]{
\color{xAddr}\small\vspace{-3mm}
Our Department\\
Our University\\
Our Address -- a longer line\\
Our phone number -- Our e-mail}
}
\pagestyle{plain}
I've added some images to the header, just in case here they are:

mwe.tex:
\documentclass[12pt]{mwe}
\usepackage{lipsum}
\begin{document}
\begin{Large}Yay, a document!\end{Large}
\lipsum[3-12]
\end{document}
Two runs with pdflatex gives this:
Looking good! But now I want to add a number to each page. I could add a \thepage in any position on the footer, but I'd rather have the number on the right side of the footer:
Based on TikZ full page with absolute node positioning I've tried to define a tikz figure with
\newcommand{\mypagenumber}{
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north,minimum height=0.7cm, minimum width=2cm] (names)
at ([xshift=8.5cm,yshift=3cm]current page.south) {\color{xLine}\Large\thepage};
\end{tikzpicture}}
and this to the definition of \fancypagestyle
\chead{\mypagenumber} % Why not? as long as it appears on every page
(added these to mwe.cls)
Results are almost what I want: pages 1-9 looks OK:
But as soon as I get two digits on the number page alignment gets bad:
Finally, here are the questions:
- How can I define my tikzpicture so the number will be right-aligned with the horizontal line over the footer, even if I change the text size or font?
- Is it possible to define the values (anchors, shifts, etc.) in tikzpicture in such a way that if I change the page margins or paper size I don't need to change these values? E.g. is it possible to make the tikzpicture position relative to the line over the footer?
- It works but it seems a ugly hack, is there a better/simpler/more robust way?
EDIT -- UPDATE
Here's something that works (based on a different tikz issue in Left and right align inside one TiKZ rectangular node):
\newcommand{\mypagenumber}{
\begin{tikzpicture}[remember picture,overlay]
\node[fill=gray!20,anchor=north,minimum height=0.7cm,
text width=3cm,align=flush right] (names)
at ([xshift=6.97cm,yshift=3cm]current page.south)
{\color{xLine}\hfill\Large\bf\thepage};
\end{tikzpicture}}
There is a gray background to help visualize the alignment:
Still questions 2 and 3 remain, I had to adjust the xshift parameter until I got the results I wanted -- not sure it is robust. Any help appreciated.
Thanks, Rafael






leftto\node[anchor=north,...]help? – Feb 04 '18 at 21:12anchor=northtoanchor=north east. However, this probably isn't the best way to do it. (I mean, this method generally.) – cfr Feb 04 '18 at 21:19align=flush leftandalign=flush right-- funny, no change at all. I'm searching fortikz align text inside node. – Rafael Santos Feb 04 '18 at 22:32tikzpagenodespackage... – Paul Gaborit Feb 04 '18 at 23:17xshift, too. If you want people to play with your code, provide a minimal working example which shows the problem. – cfr Feb 05 '18 at 00:28tikzpagnodesmade it much simpler. I still have to set xshift and yshift, but the values are related to the size of the node. I changed the page margins just to test and the page is still on the intended position. Thanks! – Rafael Santos Feb 05 '18 at 01:18Our Department \hfill {\Large\thepage}\\? – Feb 05 '18 at 08:45~\hfill Our Department \hfill \thepagesolves it. – Feb 05 '18 at 22:57tikzfor simple things like this is a waste of time. – Feb 05 '18 at 23:14tikzallows more flexibility, from what I learned from the solutions and comments. And learning is seldom a waste of time. – Rafael Santos Feb 06 '18 at 12:07