0

I have a header image which is exactly 7 inches in width. I made it 7 inches because I saw that the default latex margins were 1.25 inches on both sides, and I subtracted that from the default 8.25 width of the document. I was able to easily add this image in its full width on the first page using

\includegraphics{logo.png}

But obviously this doesn't apply to every page. Unfortunately, other similar questions involved people wanting the image in the upper left, or the upper right. I just want mine at the very top of each page, and with the same margins as the page.

3
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Jun 21, 2022 at 21:43
  • 2
    Take a look at the fancyhdr package. Commented Jun 21, 2022 at 22:32
  • 1
    There's an implicit assumption here that the U.S. default "lettersize" paper is being used. That's not always a safe assumption, so a little more specificity regarding what you intend would be helpful. Commented Jun 21, 2022 at 22:43

2 Answers 2

1

There are a lot of ways and packages can help you to do that depends on the document class you use. For example, in the standard article class, the easiest way to do it without using any packages is to define a new pagestyle like this:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\makeatletter
\def\ps@newheadings{%
    \def\@oddfoot{\hfil\thepage\hfil}\let\@evenfoot\@oddfoot%
    \def\@oddhead{\includegraphics[width=\linewidth,height=3cm]{example-image}}%
    \let\@evenhead\@oddhead
    }
\setlength{\headheight}{3cm}
\makeatother
\pagestyle{newheadings}
\begin{document}
\section{One}
\lipsum
\end{document}

enter image description here

In general, fancyhdr is a good package to customize the header and footer as well, following is an example using fancyhdr to achieve same result:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{fancyhdr}
\fancyhf{}
\setlength{\headheight}{89pt}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[c]{\includegraphics[width=\linewidth,height=3cm]{example-image}}
\fancyfoot[c]{\thepage}
\pagestyle{fancy}
\begin{document}
\section{One}
\lipsum
\end{document}
5
  • 1
    Thank you so much that works great! Only issue is that I have edited the margins of my page a bit, and this in addition to adding your code has resulted in the page numbers disappearing. Tried removing the custom margins, but still no avail. How can I re-add the page numbers to the footer? Commented Jun 22, 2022 at 20:09
  • 1
    @Steveman30290 That's probably caused by the bottom margin too short and make the page number out of page bottom, you could try set footskip to a smaller value. Are you using geometry package to set the margin?
    – Tom
    Commented Jun 22, 2022 at 20:15
  • 1
    Thanks Tom, I am indeed using geometry to set the margins. Commented Jun 22, 2022 at 20:17
  • 1
    @Steveman30290 You better provide the MWE to show the problem, include the code from \documentclass to end{document}. Take a look this. tex.meta.stackexchange.com/questions/228/…
    – Tom
    Commented Jun 22, 2022 at 20:20
  • 1
    @Steveman30290 In this way, people don't need to guess what did you used. People can compile you code and give advice on your particular case. You can add those to you question by editing it right now.
    – Tom
    Commented Jun 22, 2022 at 20:23
1

You can use the fancyhdr Package see minmal example below:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr} % Package Layout Headerline
\usepackage{graphicx} % Package Insert Graphics

\title{Article}
\author{Yan}
\date{\today}



\begin{document}

% Set Header with fancyhdr package
\rhead{} % empty left head in headline
\chead{\includegraphics[width=\linewidth]{logo.png}} %insert Logo in center headline
\rhead{} % empty rigth head in headline
\setlength{\headheight}{16pt} %fixing headline warning

\maketitle
\newpage
\pagestyle{fancy}
\section{Section I}
\newpage
\section{Section II}

\end{document}

You must log in to answer this question.

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