此截图来自我的 .docx 文档。我提取了右上角的图像。但是,当我尝试定义标题时,结果非常糟糕。
如果我继续增加图片尺寸,页眉就会与正文重叠。而且,我完全不知道如何在页眉上添加页码。
有人能告诉我在这种情况下我该怎么办吗?tex 文件内容是:
\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}
答案1
您实际上希望使用更绝对的放置技术来放置角图像和页码。 其中一个选项是使用eso-pic
。您可以先放置角落图像,然后放置页码,全部放在页面的背景中。
\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
将内容添加到所有后续页面的B
确认G
轮次中。然后,eso-pic
提供一些补充放置宏,例如\AtPageUpperLeft
,将内容放在页面的左上角。由于您希望它位于右上角,我们使用框(\makebox[\paperwidth][r]
)将其移过来,并在视图中将其降低(通过\raisebox{-\height}
)。您可以以类似的方式放置页码。
由于这是发货程序的一部分,因此\thepage
将准确表示页码。
现在,页眉与角落图像/页码分开,您可以不受干扰地管理它们。