1

I am using the titlepage environment for my first page and added it to the page counter \stepcounter{page} without showing it. I created a fancy header and footer that I want to show on all pages except the title page. I then added two more pages like this: \newpage\chapter*{Summary}.

The problem is that footer and header are showing on all pages, except the first and second one. On the second page, I can see the fancy header but not the fancy footer. Thinking there might be a problem with the margins of the document, I tried to modify some but I always have the problem.

Here is a sample of the tex file :

%footer and header
\setlength {\marginparwidth }{2cm}
\fancyfoot[L]{\textcolor{red}{\fbox{CONFIDENTIEL ENTREPRISE}}}
\fancyfoot[R]{ENTREPRISE NAME \qquad\newref{tableofcontents}}
\fancyhead[R]{SUBJECT} 
\fancyhead[L]{Name}

%title page
\newcommand{\CustomTitle}{
    \begin{titlepage}
    \newgeometry{left=6cm,bottom=2cm, top=1cm, right=1cm}
    \tikz[remember picture,overlay] \node[opacity=1,inner sep=0pt] at (2.2mm,-165mm){\includegraphics{Fond1.png}};
    \fontfamily{fvs}\fontseries{m}\selectfont
    \color{white}
    \begin{picture}(0,0)
    \put(-110,-743){\rotatebox{90}{\Huge{Subject}}}
    \end{picture}
    \vspace{-15mm}
    \begin{center}
        \includegraphics[width=5cm]{logo.png}
        \qquad
        \includegraphics[width=5cm]{logo2.png}
    \end{center}               
        
    \flushright
    \vspace{10mm}
    \fontfamily{cmss}\fontsize{22}{28}\selectfont\textcolor{blue2}{Name of the subject}
    
    \normalsize
    \color{black}
    
    \vspace{1.5cm}
    \normalsize
    
    \vspace{15mm}
    
    \textbf{Date}\\
    \vspace{50mm}
    \Large\textbf{Author}\\
    \vfill
    \textcolor{red}{\fbox{CONFIDENTIEL ENTREPRISE}}
    \end{titlepage}
    \stepcounter{page}
}
\begin{document}

\setstretch{1,2}

\setcounter{page}{1}
\CustomTitle
%\pagenumbering{arabic}

%first page
\newpage
\chapter*{firstpage}
\vspace{2mm}
sample of the first page
%second page
\chapter*{second page}
\vspace{2mm}
sample of the second page
\end{document}
1
  • 1
    Welcome. // Your code appears to be quite complete. Can you please Edit your question to add the missing beginning? This way we can copy & compile more easily.
    – MS-SPO
    Jul 27, 2022 at 15:38

2 Answers 2

3

(1) Define the plain style. Chapters start on a new page with the plain style as default.

(2) Apply the plain style it to the entire document using \pagestyle{plain}

Now all the pages will use the same style except for the title page which uses the empty style.

(3) Restore the default geometry after the title page.

c

d

% !TeX TS-program = pdflatex

\documentclass[12pt,a4paper, openany]{book}

\usepackage{graphicx}
\usepackage[top=3.00cm, headheight=16.0pt]{geometry} % expand the header space

\usepackage{tikz}

\usepackage{fancyhdr}
\fancypagestyle{plain}{% 
    \renewcommand\headrulewidth{0pt}
    \fancyhf{} %clear header and footer
    %footer and header
    \fancyfoot[L]{\textcolor{red}{\fbox{CONFIDENTIEL ENTREPRISE}}}
    \fancyfoot[R]{ENTREPRISE NAME }
    \fancyhead[R]{SUBJECT} 
    \fancyhead[L]{Name}
    \fancyfoot[C]{\thepage }
}
\pagestyle{plain} % apply the style to the full document <<<<<<<<<<<<<<<<<

%title page
\newcommand{\CustomTitle}{%
    \begin{titlepage}
        \newgeometry{left=6cm,bottom=2cm, top=1cm, right=1cm}
        \tikz[remember picture,overlay] \node[opacity=1,inner sep=0pt] at (2.2mm,-165mm){\includegraphics{example-image}};
        \fontencoding{T1}\fontfamily{fvs}\selectfont % changed <<<<<<<<<<<<<<<<<<<<<,
        \color{white}
        \begin{picture}(0,0)
            \put(-110,-743){\rotatebox{90}{\Huge{Subject}}}
        \end{picture}
        \vspace{-15mm}
        \begin{center}
            \includegraphics[width=5cm]{example-image-a}
            \qquad
            \includegraphics[width=5cm]{example-image-b}
        \end{center}               
        
        \flushright
        \vspace{10mm}
        \fontfamily{cmss}\fontsize{21}{28}\selectfont\textcolor{blue}{Name of the subject}
        
        \normalsize
        \color{black}
        
        \vspace{1.5cm}
        \normalsize
        
        \vspace{15mm}
        
        \textbf{Date}\\
        \vspace{50mm}
        \Large\textbf{Author}\\
        \vfill
        \textcolor{red}{\fbox{CONFIDENTIEL ENTREPRISE}}
    \end{titlepage}
    \restoregeometry % needed <<<<<<<<<<<<<<<<<<<<<<<   
}

\begin{document}
    
    \CustomTitle

    \chapter*{firstpage}
    \vspace{2mm}
    sample of the first page
    %second page
    \chapter*{second page}
    \vspace{2mm}
    sample of the second page
\end{document}
1
  • Oh this is great ! Thank you ! Your \restoregeometry command did the trick, didn't know that
    – Foufi
    Jul 28, 2022 at 9:11
2

The titlepage uses pagestyle plain. The next page is probably a chapter opening page which also uses that style.

So you would have to redefine the pagestyle plain to use the same footer.

This will probably work:

\fancypagestyle{plain}{
  \renewcommand\headrulewidth{0pt}
  \fancyhead{}
}

It will inherit the footer from pagestyle fancy. Otherwise just copy the footer definitions inside the above definition.

As you code is incomplete, I cannot test it in your situation, so no guarantee.

You must log in to answer this question.

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