This is a very interesting question and I would like to provide a comprehensive solution for document class article. This solution uses the packages geometry, fancyhdr, pgf, scrextend and textpos, it looks complicated at the beginning, but trust me, it is nice and clean and do not require adjustment even when you change page geometry.
The usage of the packages are, geometry is used to setup the page geometry, fancyhdr is used to produce the header, pgf is used to define length, scrextend is used to find out if current page is an even page or odd page, and finally textpos is used to place the text.
I also added text block at the top left corner.
Here is the code
% !TEX encoding = UTF-8 Unicode % !TEX TS-program = xelatex \documentclass[UTF8]{article} \usepackage[b4paper, twoside]{geometry} %% you can set page to be 'a4paper' or 'c5paper' or 'legalpaper' or whatever provided by 'geometry', no other adjustment is needed %% even and odd page are set to have different margin size, you can set margin size to be equal by removing 'twoside', no other adjustment is needed \usepackage{lipsum} %% generate random texts \usepackage{fancyhdr} %% produce header \usepackage{pgf} %% define length \usepackage[absolute, overlay]{textpos} %% put text blocks at absolute position \usepackage{scrextend} %% check if current page is even or odd \pgfmathsetlengthmacro{\texttop}{1.0 in + \voffset + \topmargin + \headheight + \tabcolsep} %% this is the very top of the body \pgfmathsetlengthmacro{\textrightodd}{1.0 in + \oddsidemargin + \hoffset + \textwidth} %% this is the right edge of the body for odd page \pgfmathsetlengthmacro{\textrighteven}{1.0 in + \evensidemargin + \hoffset + \textwidth} %% this is the right edge of the body for even page \pgfmathsetlengthmacro{\textleftodd}{1.0 in + \oddsidemargin + \hoffset} %% this is the left edge of the body for odd page \pgfmathsetlengthmacro{\textlefteven}{1.0 in + \evensidemargin + \hoffset} %% this is the left edge of the body for even page \setlength{\TPHorizModule}{1.0 pt} %% set the unit used by 'textpos' to be 'pt' because the length returned by 'pdf' macros are in 'pt' \pagestyle{fancy} %% set up page header \lhead{left head} \chead{center head} \rhead{page \thepage} \cfoot{} \begin{document} \title{title} \date{\today} \author{author} \ifthispageodd{\textblockorigin{\textleftodd}{\texttop}}{\textblockorigin{\textlefteven}{\texttop}} %% set the origin used by 'textpos' at top left of page for even and odd pages differently \pgfmathwidth{"note for page \thepage"} %% store the length of wanted text into '\pgfmathresult' \begin{textblock}{\pgfmathresult}[0, 0](0, 0) %% '[0, 0]' sets top left corner of text block to be used as anchor point, '(0, 0)' sets the anchor point right at the origin of 'textpos' \noindent note for page \thepage \end{textblock} \ifthispageodd{\textblockorigin{\textrightodd}{\texttop}}{\textblockorigin{\textrighteven}{\texttop}} %% set the origin used by 'textpos' at top right of page for even and odd pages differently \pgfmathwidth{"note for page \thepage"} \begin{textblock}{\pgfmathresult}[1, 0](0, 0) %% '[1, 0]' sets top right corner of text block to be used as anchor point, '(0, 0)' sets the anchor point right at the origin of 'textpos' \noindent note for page \thepage \end{textblock} \maketitle \thispagestyle{fancy} \lipsum[6] \newpage \ifthispageodd{\textblockorigin{\textleftodd}{\texttop}}{\textblockorigin{\textlefteven}{\texttop}} \pgfmathwidth{"note for page \thepage"} \begin{textblock}{\pgfmathresult}[0, 0](0, 0) \noindent note for page \thepage \end{textblock} \ifthispageodd{\textblockorigin{\textrightodd}{\texttop}}{\textblockorigin{\textrighteven}{\texttop}} \pgfmathwidth{"note for page \thepage"} \begin{textblock}{\pgfmathresult}[1, 0](0, 0) \noindent note for page \thepage \end{textblock} \lipsum[2] \newpage \ifthispageodd{\textblockorigin{\textleftodd}{\texttop}}{\textblockorigin{\textlefteven}{\texttop}} \pgfmathwidth{"note for page \thepage"} \begin{textblock}{\pgfmathresult}[0, 0](0, 0) \noindent note for page \thepage \end{textblock} \ifthispageodd{\textblockorigin{\textrightodd}{\texttop}}{\textblockorigin{\textrighteven}{\texttop}} \pgfmathwidth{"note for page \thepage"} \begin{textblock}{\pgfmathresult}[1, 0](0, 0) \noindent note for page \thepage \end{textblock} \lipsum[3] \newpage \ifthispageodd{\textblockorigin{\textleftodd}{\texttop}}{\textblockorigin{\textlefteven}{\texttop}} \pgfmathwidth{"note for page \thepage"} \begin{textblock}{\pgfmathresult}[0, 0](0, 0) \noindent note for page \thepage \end{textblock} \ifthispageodd{\textblockorigin{\textrightodd}{\texttop}}{\textblockorigin{\textrighteven}{\texttop}} \pgfmathwidth{"note for page \thepage"} \begin{textblock}{\pgfmathresult}[1, 0](0, 0) \noindent note for page \thepage \end{textblock} \lipsum[4] \end{document}
here is what is produced

For the page geometry, you can refer to this figure
