1

Following up, my question is now to replace the text of the heading with a dummy text. I tried multiple options at Line 16, but the text does not seem to go above the margin. Assuming this is solvable, the problem still remains as how to find the exact location for the header text.

% Shamelessly copied from https://www.overleaf.com/learn/latex/Headers_and_footers
\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}


% https://tex.stackexchange.com/a/572688/38244
%%%%%%%%% How to get the heading location?
\usepackage{eso-pic}
\AddToShipoutPictureFG{% Place something in the page ForeGround...
    \AtTextUpperLeft{% ...at the text block upper left corner...
        \ifnum\value{page}=3 % ...only on page 3...
        \makebox[\textwidth]{% ...in the horizontal centre of the text block...
            \raisebox{\dimexpr-.5\height-.5\textheight}{% ...at the vertical centre of the text block
                \Huge RaNDoM TeXT 
            }%
        }%
        \fi
    }%
}

\pagestyle{fancy}
\fancyhf{}
\rhead{Overleaf}
\lhead{Guides and tutorials}
\rfoot{Page \thepage}

\begin{document}
    
    \section{First Section}
    
    Hello,  here  is  some  text  without  a  meaning.   This  
    text  should  show  what  a printed text will look like at 
    this place.  If you read this text, you will get no information.  
    Really?  Is there no information?  Is there a difference between 
    this ...
    
    \lipsum[1-50]
    
    %%%%%%%%%%% Write something on the header of page 3 to replace the current heading
\end{document}
3
  • \lhead{\ifnum\value{page}=3\relax RaNDoM TeXT\else Guides and tutorials\fi} instead of \lhead{Guides and tutorials}? (Or analogously for \rhead?)
    – user229669
    Commented Nov 29, 2020 at 5:46
  • @hola: This is exactly the reason why you should supply a complete, minimal example with a clear description of what you want to achieve. The linked question does what you want, but you had to ask a second question specifically pointing to the header being of importance. Including that in your first question would have solved the problem there.
    – Werner
    Commented Nov 29, 2020 at 5:52
  • @Werner I understand your point. :-) In my defense, I first thought writing in the middle of page would work, but at the end it didn't look good.
    – hola
    Commented Nov 29, 2020 at 16:05

1 Answer 1

1

There is no need for using eso-pic if you only want to place content in the headers conditionally. For that, just place your condition directly inside the header/footer:

\documentclass{article}

\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{}
\rhead{\ifnum\value{page}=3 Not Overleaf\else Overleaf\fi}
\lhead{\ifnum\value{page}=3 Something else\else Guides and tutorials\fi}
\rfoot{Page \thepage}

\begin{document}

\section{First section}
\sloppy\lipsum[1-50]

\end{document}
2
  • Why is \sloppy required/what is it doing?
    – hola
    Commented Jun 5, 2021 at 21:57
  • @hola: It's not required. However, it avoids a number of bad \hbox warnings when printing \lipsum text (for which TeX has no proper hyphenation patterns).
    – Werner
    Commented Jun 6, 2021 at 18:42

You must log in to answer this question.

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