后续行动,我现在的问题是将标题文本替换为虚拟文本。我在第 16 行尝试了多个选项,但文本似乎没有超出边距。假设这是可以解决的,问题仍然是如何找到标题文本的确切位置。
% 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}
答案1
无需使用eso-pic
如果您只想有条件地将内容放在页眉中。为此,只需将您的条件直接放在页眉/页脚中:
\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}