Text FormattingLetter Header Missing First Page

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
chmst1999
Posts: 4
Joined: Sun Feb 24, 2019 7:54 am

Letter Header Missing First Page

Post by chmst1999 »

I am unable to figure out how to get the same header on all pages of this document. It shows up on everything but the first page, but I can't seem to get it on page 1. Can anyone help fix this problem? The following document works in my editor, but has a few errors. If there is an easier way to set this up correctly please let me know.

Here is what I want:
1. same header on all pages
2. line under header on all pages
3. be able to adjust the distance the text starts from the line below the header

Code: Select all

\documentclass[12pt]{letter} % Uses 10pt
\usepackage[document]{ragged2e}
\usepackage{makecell}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}

\geometry{
 letter, includehead, includefoot,
 total={170mm,257mm},
 headheight=5mm,
 left=20mm,
 }
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=blue}
    
%Header
\makeatletter
\thispagestyle{plain}
\def\ps@myheader{
  \def\@oddhead{%\includegraphics[height=20mm,left]{example-image}\hfil}
   \let\@evenhead\@oddhead% make right page headers the same as left
		 \centering
 		\begin{tabularx}{\textwidth}{ccc}
        	 &\textsc{\large\bf First A. Last}& \\
          	 &\textsc{P.O. BOX 999, Square, ZZ 11223}&  \\ 
          	\textsc{\Mobilefone \hspace{1mm} (555) 555-5555} & \textsc{\Letter \hspace{1mm}  email@schools.k12.zz.us} & \href{http://goo.gl/AAAA}{http://goo.gl/AAAA}
%\hline
        \end{tabularx}%
 }
 \end{centering}
}

\begin{document}
   \let\@evenhead\@oddhead% make right page headers the same as left
\pagestyle{myheader}

\signature{First And Last}           % name for signature 
\longindentation=0pt                       % needed to get closing flush left
\let\raggedleft\raggedright                % needed to get date flush left
 
\begin{letter}{Mr. Whom Ever\\Superintendent\\P.O. Box 8888\\Smallville, YY 76543}
\opening{Dear Mr. Ever:}

page 1
    \newpage
    page 2
    \newpage
   page 3

\vspace{\baselineskip}\linebreak
\closing{Sincerely,} 
\encl{enclosure 1, enclosure 2}		% Enclosures
\end{letter}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Letter Header Missing First Page

Post by Johannes_B »

Welcome to the forum.

Code: Select all

\documentclass[12pt,headsepline]{letter} % Uses 10pt
\usepackage[document]{ragged2e}
\usepackage{makecell}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{geometry}

\geometry{
letterpaper,% <------- corrected
 includehead, includefoot,
total={170mm,257mm},
headheight=5mm,
left=20mm,
head=58.99994pt,%<------ added
}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=blue}

%Header
\usepackage{blindtext}
\usepackage{marvosym}
\usepackage{scrlayer-scrpage}
\chead{
\begin{tabularx}{\textwidth}{ccc}
&\textsc{\large\bf First A. Last}& \\
&\textsc{P.O. BOX 999, Square, ZZ 11223}& \\ 
\textsc{\Mobilefone \hspace{1mm} (555) 555-5555} & \textsc{\Letter \hspace{1mm} email@schools.k12.zz.us} & \href{http://goo.gl/AAAA}{http://goo.gl/AAAA}
%\hline
\end{tabularx}%
}

\begin{document}

\signature{First And Last} % name for signature 
\longindentation=0pt % needed to get closing flush left
\let\raggedleft\raggedright % needed to get date flush left

\begin{letter}{Mr. Whom Ever\\Superintendent\\P.O. Box 8888\\Smallville, YY 76543}
\opening{Dear Mr. Ever:}\thispagestyle{scrheadings}

\blindtext[22]

\vspace{\baselineskip}%\linebreak Doesn't make any sense
\closing{Sincerely,} 
\encl{enclosure 1, enclosure 2}	% Enclosures
\end{letter}
\end{document}

I would probably use some KOMA-stuff here.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
chmst1999
Posts: 4
Joined: Sun Feb 24, 2019 7:54 am

Letter Header Missing First Page

Post by chmst1999 »

Thank you! I had some trouble compiling the email in your fix. I tried \email but I think I’ll have to define that.

Your fixes work well. However, now I have the pages numbered in the top left corner. Is there a way to remove that? I don’t see where it is being directed to number the pages.

Again, thank you!
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Letter Header Missing First Page

Post by Johannes_B »

I thought the letter symbols is what you want based on the code you shared.


Anyway, if you don't want the page numbers, add \ihead*{}.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
chmst1999
Posts: 4
Joined: Sun Feb 24, 2019 7:54 am

Letter Header Missing First Page

Post by chmst1999 »

Johannes your work is great. This version is much better than what I had. The only thing still in there is the page numbers on the left side of the header. I don't know where to put the \ihead*{} to remove that. If I can get rid of those, this will be exactly what I need. Thanks for your help!

UPDATE: I fixed it with the line below included after the start of the document (in %%%%%)
\pagenumbering{gobble} % stops page numbering throughout document

Now the document and header work as I want without the page numbering!

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Welcome to Overleaf --- just edit your LaTeX on the left,
% and we'll compile it for you on the right. If you open the
% 'Share' menu, you can invite other users to edit at the same
% time. See http://www.overleaf.com/learn for more info. Enjoy!
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[12pt,headsepline]{letter} % Uses 10pt
\usepackage[document]{ragged2e}
\usepackage{makecell}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{geometry}
 
 
\geometry{
letterpaper,% <------- corrected
 includehead, includefoot,
total={170mm,257mm},
headheight=5mm,
left=20mm,
head=58.99994pt,%<------ added
}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=blue}
 
%Header
\usepackage{blindtext}
\usepackage{marvosym}
\usepackage{scrlayer-scrpage}
\newcommand*{\email}[1]{\href{mailto:#1}{\nolinkurl{#1}}}
\ihead*{}
\chead{
\begin{tabularx}{\textwidth}{ccc}
&\textsc{\large\bf First A. Last}& \\
&\textsc{P.O. BOX 999, Square, ZZ 11223}& \\ 
\textsc{\Mobilefone \hspace{1mm} (555) 555-5555} & \textsc{\Letter \hspace{1mm} \email{anyone@anywhere.k12.mt.us}} & \href{http://goo.gl/AAAA}{http://goo.gl/AAAA}
%\hline
\end{tabularx}%
}
 
\begin{document}
 
\signature{First And Last} % name for signature 
\longindentation=0pt % needed to get closing flush left
\let\raggedleft\raggedright % needed to get date flush left

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagenumbering{gobble} % stops page numbering throughout document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

\begin{letter}{Mr. Whom Ever\\Superintendent\\P.O. Box 8888\\Smallville, YY 76543}
\opening{Dear Mr. Ever:}\thispagestyle{scrheadings}
 
\blindtext[10]
 
\vspace{\baselineskip}%\linebreak Doesn't make any sense
\closing{Sincerely,} 
\encl{enclosure 1, enclosure 2}	% Enclosures
\end{letter}
\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Letter Header Missing First Page

Post by Stefan Kottwitz »

\ohead{} instead of \ihead*{} would work here.

Stefan
LaTeX.org admin
Post Reply