3

As described in the title. What I'm trying to design is this: enter image description here

This screenshot is from my .docx document. I have extracted the upper-right image. However, when I'm trying to define the header, I got a very bad result.

enter image description here

If I keep increasing the image size, the header will overlap with the main text. And, I have completely no idea how to add the page number on it.

Could anyone let me know what I should do in this case? The tex file content is:

\documentclass[12pt]{article}
\usepackage[
  a4paper,
  margin=1in,
  headsep=18pt, % separation between header rule and text
]{geometry}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{microtype}
\usepackage{color}

\newcommand{\statement}[1]{\medskip\noindent \textcolor{black}{\textbf{#1}}\space }

\pagestyle{fancy} \fancyhf{} \fancyhead[L]{ \textcolor{gray}{Name}} \fancyfoot[C]{\footnotesize\thepage} \rhead{\textcolor{gray}{Institution}\includegraphics[width=1.5cm]{header.png}} \let\oldcenter\center \let\oldendcenter\endcenter \renewenvironment{center}{\setlength\topsep{0pt}\oldcenter}{\oldendcenter}

\newcommand{\wordcount}{ \begin{center} \rule{0.75\textwidth}{.4pt}\ {\footnotesize A statement of \numwords \ words} \end{center} }

\newif\ifcomments

\newcommand{\comment}[1]{} \newcommand{\todo}[1]{\ifcomments\textcolor{red}{TODO: #1}\fi}

%%%%%%%%%%%%%%%%%%%%% Edit this section %%%%%%%%%%%%%%%%%%%%

\commentstrue

\newcommand{\soptitle}{Statement of Purpose} \newcommand{\yourname}{My Name} \newcommand{\yourintent}{Applicant for a PhD in The Thing} \newcommand{\school}{The University} \newcommand{\advisorfirstname}{FirstName} \newcommand{\advisorlastname}{LastName} \newcommand{\advisorfull}{Prof. \advisorfirstname \ \advisorlastname} \newcommand{\advisor}{Prof. \advisorlastname} \newcommand{\numwords}{\todo{number}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[ breaklinks, pdftitle={\yourname - \soptitle}, pdfauthor={\yourname}, unicode, colorlinks, urlcolor={blue!80!black} ]{hyperref}

\begin{document}

\statement{Introduction} I want to work with \advisorfull. \advisor \ is good. \href{https://www.google.com}{Here} is my website.\footnote{Footnote} \wordcount

\end{document}

  • You need to hide the picture size. See for example https://tex.stackexchange.com/questions/367158/header-page-book-in-tikz – Rmano Jan 24 '24 at 06:47

1 Answers1

3

You effectively want to place both the corner image and the page number using a more absolute placement technique. One such option is to use eso-pic. You can place the corner image first, then the page number, all in the background of the page.

enter image description here

\documentclass{article}

\usepackage[ a4paper, margin=1in, headsep=18pt, % separation between header rule and text ]{geometry} \usepackage{xcolor} \usepackage{fancyhdr} \usepackage{graphicx} \usepackage{eso-pic} \usepackage{lipsum}

\pagestyle{fancy} \fancyhf{}% Clear header/footer \fancyhead[L]{\textcolor{gray}{Name}} \fancyhead[R]{\textcolor{gray}{Institution}}

\begin{document}

\AddToShipoutPictureBG{% % Place corner image in background of all pages \AtPageUpperLeft{% Move to upper left corner \raisebox{-\height}{% Drop content by its entire height, so it is placed on the page \makebox[\paperwidth][r]{% Push corner to the right of the page \includegraphics{corner}% Insert corner image }% }% }% % Add page number on top of corner image \AtPageUpperLeft{% \raisebox{\dimexpr-\height-2\baselineskip}{% Drop lower on page \makebox[\paperwidth][r]{% \textcolor{white}{\bfseries\thepage}% \hspace{2em}% Push away from right margin }% }% }% }

\lipsum

\end{document}

\AddToShipoutPictureBG adds content to the BackGround of all subsequent pages. Then, eso-pic provides some supplementary placement macros, like \AtPageUpperLeft, which puts the content at the upper left corner of the page. Since you want it at the upper right corner, we move it over using a box (\makebox[\paperwidth][r]) and lower it within view (via \raisebox{-\height}). In a similar way you can place the page number.

Since this forms part of the shipout procedure, \thepage will be an accurate representation of the page number.

With the header now separate from the corner image/page number, you can manage them without interference.

Werner
  • 603,163