Search code examples
latexoverleaf

When using the fancyhdr package, the header part repeats on every page on Latex. How can I avoid repetition as I want header only on 1st page?


I employed the use of "data-science-tech-resume-template" template on overleaf for building my own resume. The "_header.tex" file contains the use of 'fancyhdr' package and used lheader and rheader to display my name, enail id, contact etc. However, this header part repeats on evey page. 1st Page 2nd Page

Below is the code for _header.tex:

\RequirePackage{fancyhdr}
    \fancypagestyle{plain}{%
    \fancyhf{}
    \lhead{
    
            \HUGE \skills \name \vspace{-.32em}
            \\ % feel free to adjust vspace to 0 
        {
                \color{highlight} \Large{\role}
            }
    } 
    \rhead{
        
            \city \\  % city 
            \phone \\ % PHONE    
            \href{mailto:\email}{\email} \\
            % \href{https://github.com/\github}{github.com/\github} \\% Github
            \href{https://www.linkedin.com/in/\LinkedIn}{linkedin.com/in/\LinkedIn}
    } 
\renewcommand{\headrulewidth}{1pt}% 2pt header rule
\renewcommand{\headrule}{\hbox to\headwidth{%
  \color{highlight}\leaders\hrule height \headrulewidth\hfill}}
}
\pagestyle{plain}

\setlength{\headheight}{90pt}
\setlength{\headsep}{5pt}

I want the header to avoid repeating on the 2nd page. Can someone please help me out with this as I am new to this?


Solution

  • I think I found a solution that might help you.

    • First, you need to move \RequirePackage{fancyhdr} from _header.tex to TLCresume.sty.
    • Second, delete \fancypagestyle{plain} from _header.tex and change \pagestyle{plain} to \pagestyle{fancy}.
    • Third, create a new file (e.g. test.tex) which contains the content of the 2nd page and change the code of resume.tex.

    This is how the modified resume.tex file looks like.

    \begin{document}
    
    % input header goes inside "document"
    \input{_header}
    
    \input{sections/objective}
    
    \section{Skills}
    \input{sections/skills}
    
    \section{Technical Experience}
    \input{sections/experience}
    
    \section{Education}
    \input{sections/education}
    
    \section{Activities}
    \input{sections/activities}
    
    % this is where 2nd page starts
    \newpage
    \pagestyle{plain}
    \setlength{\headheight}{50pt}
    \setlength{\headsep}{0pt}
    
    % content of the 2nd page
    \section{Test}
    \input{sections/test}
    
    \end{document}