Templates – How to Resolve Issues with LaTeX Template Using Fancyhdr

fancyhdrsublime-texttemplates

For all my documents, I created a template.tex file which is imported in all my files. But it says that I got those issues :

/home/rperrod/rp/PERSO/LaTeX/Test/template/t.tex:20: Undefined control sequence. [  \setlength{\footheight}{10mm}]
/home/rperrod/rp/PERSO/LaTeX/Test/template/t.tex:20: LaTeX Error: Missing \begin{document}. [  \setlength{\footheight}{10mm}]
/home/rperrod/rp/PERSO/LaTeX/Test/template/t.tex:25: Undefined control sequence. [  \allowdisplaybreaks]

Heres my test file :

    \documentclass[a4paper, 12pt]{article}
    
      \usepackage[english, french]{babel}
      \usepackage{fancyhdr}
      \usepackage{geometry}
      \usepackage{varwidth}
      
    %----------- My template file ---------
      
      \geometry{
        a4paper,
        left=16mm,
        top=16mm,
        bottom=16mm,
        right=16mm
      }
    
      \pagestyle{fancy}
      \fancyhf{}
      \setlength{\headheight}{10mm}
      \lhead{\textsc{Some Text}}
      \rhead{\textsc{SOME} Text}
      \setlength{\footheight}{10mm}
      \rfoot{\thepage}
      \date{}
      \author{}
    
      \allowdisplaybreaks
    
    %-----------------------------------
    
      \title{I'm a giraffe}
    
    \begin{document}
    
      \maketitle\thispagestyle{fancy}
    
      Lorem ipsum
    
      \section{Colorado}
    
      \newpage
    
      \newpage
    
      \section{Says}
    
      \newpage
    
      \section{Giraaaaaaaaaaaaaaaffe}
    
    \end{document}

Where's the issue ? I just copied this from my friend and for him, it works. Did I forget a certain package ?

Best Answer

It is better to include headheight and footskip (not footheight) in the geometry definition, rather than separately with \setlength.

\documentclass[a4paper, 12pt]{article}

  \usepackage[english, french]{babel}
  \usepackage{fancyhdr}
  \usepackage{geometry}
  \usepackage{varwidth}
  \usepackage{amsmath}
  
%----------- My template file ---------
  
  \geometry{
    a4paper,
    left=16mm,
    top=16mm,
    bottom=16mm,
    right=16mm,
    headheight=10mm,
    footskip=10mm,
  }

  \pagestyle{fancy}
  \fancyhf{}
  \lhead{\textsc{Some Text}}
  \rhead{\textsc{SOME} Text}
  \rfoot{\thepage}
  \date{}
  \author{}

  \allowdisplaybreaks

%-----------------------------------

  \title{I'm a giraffe}

\begin{document}

  \maketitle\thispagestyle{fancy}

  Lorem ipsum

  \section{Colorado}

  \newpage

  \newpage

  \section{Says}

  \newpage

  \section{Giraaaaaaaaaaaaaaaffe}

\end{document}