3

I'm using documentclass article. I want the page number to appear on the top-right corner and heading on the top-left corner. Though I want page numbering in every page, I don't want the heading on the very first page. When I'm using \pagestyle{fancy} and \lhead{My Header}, I'm getting the header on the desired position. However, the page number is in the bottom and there is a horizontal line under the header which I don't want. On the other hand when I'm using \pagestyle{headings}, I'm getting the page numbering correct but no title.

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{headings}

\begin{document}
This gives the page number on top-right, but no title in any page
\end{document}

and

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{My header} 

\begin{document}
This gives the header on top-left, but with a 
horizontal bar and the page number in bottom-middle
\end{document}

How to put the header on top-left and the page number on top-right without any horizontal line? Also, I don't want the header on the first page, I just want the page number on the first page.

Edit: Here are two photos of the page I'm trying to reproduce. enter image description hereenter image description here

1
  • 1
    The answers show you what you need. Be forewarned that \maketitle ends with its own \thispagestyle, so your \thispagestyle would need to come after it.
    – Teepeemm
    Feb 18, 2020 at 17:01

2 Answers 2

2

The following example should meet your requirements. It defines a firstpage page style with nothing but the page number at the top right, and it sets the fancy page style to produce some text ("My header", following your example) on the top left, the page number on the top right, and nothing on the foot of the page.

\documentclass{article}
\usepackage{fancyhdr}
\lhead{My header}
\rhead{\thepage}
\cfoot{}
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{firstpage}{%
    \lhead{}
    \rhead{\thepage}
    \cfoot{}
}
\pagestyle{fancy}
\begin{document}
\thispagestyle{firstpage}
This is the first page, without header on the left, and with the page number at the right.
\newpage
This is another page, with a header on the left and the page number on the right.
\end{document}

This is the head of the first page of the output:

and this is the head of the second page of the output:

2

Hi Abdul Muhaymin and Welcome to TeX-SE.

Assuming you really only want to remove the section name -- which is given with the command \leftmark at the MWE below -- then you can use the \thispagestyle{plain} at the very beginning of your document.

If you want something like "don't show this/that every first page of section/chapter", then a different approach is needed.

\fancyhf{} removes the bottom page number bothering you.

\fancypagestyle{plain} defines how the style will behave, in this case, plain.

\pagestyle{headings} defines the style to the whole document.

\renewcommand{\headrulewidth}{0pt} is a very cheap method to remove the line you mentioned.

A MWE with some options to fancypagestyle and some figures follow.

\documentclass{article}
\usepackage{lipsum}

\usepackage{fancyhdr}
\fancypagestyle{plain}{% change predefined style 
    \fancyhf{} % clear all header and footer fields 
    \fancyhead[R]{\thepage}
    %   \fancyhead[RO,LE]{\thepage} % Right Odd, Left Even => Outside
%   \fancyhead[L]{\leftmark} % except the left top corner 
    \renewcommand{\headrulewidth}{0pt} % remove line between header and main text 
}
\pagestyle{headings} % fancy, headings, myheadings

\begin{document}
\section{ONE DIMENSIONAL}
\thispagestyle{plain}
\lipsum[1-10]
\section{1D Harmonic}
\lipsum[1-10]
\end{document}

The very first page doesn't have the section name on the header. enter image description here

The following pages have.

enter image description here

enter image description here

2
  • 2
    Hi! @FHZ Thanks for the warm welcome. Both of the answers here work perfectly for my purpose. I actually didn't add any sections. It's just a header for all pages except the very first one. Your code is certainly useful for more general cases. So I chose vincent's answer as accepted because it addresses my problem specifically. But this answer also give a more organized approach and I appreciate that.
    – Earmen
    Feb 17, 2020 at 16:33
  • You are welcome @AbdulMuhaymin. The answers are basically the same, we just post them at the same time. Two different people came to the same solution, which is a good sign of robustness. ;)
    – FHZ
    Feb 17, 2020 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.