# Getting a tikz picture in a fancyheader for only the first page

I'm trying to insert a tikzpicture in the header of the first page of the document. If I place the tikz picture in the declaration of my \fancypagestyle{my1stpagestyle}, then the figure is indeed placed in the header (although not aligned correctly, but this could be possibly fixed with \vspace and \hspace), but also the body of the document. How can I fix this? Also, what I would like is that from the second page on, the header is just 1cm in height. I tried using geometry, but I didn't get that far.

\documentclass{article}

\usepackage[a4paper, verbose=true, nomarginpar]{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{showframe}

\definecolor{mygreen}{RGB}{112,173,71}
\definecolor{myblue}{RGB}{208,228,245}

\newcommand{\fph}{%Definition of first page header figure
\begin{tikzpicture}
\draw[fill=mygreen,color=mygreen] (0,0) rectangle (21.6,9.5);
%Braces
\draw[rounded corners = 3pt, color=myblue, line width=3pt]
(6.0,5.25)..controls(5.72, 5.3)..(5.5,5.5) -- (5.5,7.5)..controls(5.72, 7.7)..(6.0,7.75);
\draw[rounded corners = 3pt, color=myblue, line width=3pt]
(11.0,5.25)..controls(11.28,5.3)..(11.5,5.5) -- (11.5,7.5)..controls(11.28,7.7)..(11.0,7.75);
%White Line:
\draw[color=white, line width=4pt] (0.0,4.5)--(21.6,4.5);
%Document Information:
\draw(8.5,6.5) node[color=myblue] { \huge{ \textbf{ Example Title } } };
\draw(2.35,3.8) node[anchor=west, color=myblue]{\large{\textbf{Authors:}}};
\draw(2.31,3.0) node[anchor=west, color=myblue]{\large{  Mr. B., Mrs. A., Dr. C. }};
%
\draw(14.5,2.4) node[anchor=west, color=myblue]{\large{\textbf{Date:} }};
\draw(17,2.4) node[anchor=west, color=myblue]{\large{13-Mar-2013 }};
%
\draw(14.5,1.0) node[anchor=west, color=myblue]{\large{\textbf{LaTeX Document}}};
\end{tikzpicture}%
}

\geometry{
top = 0.0cm,
}

\fancypagestyle{my1stpagestyle}{
$\fph$
}
\fancyfoot[C]{First page footer}
}

\fancypagestyle{generalpagestyle}{
\fancyfoot[C]{test running footer}
}

\pagestyle{generalpagestyle}

\begin{document}
\thispagestyle{my1stpagestyle}

\LARGE{\bf \color{red} Report Summary }\\
\lipsum[1-2]
\section*{ \color{red} Main findings:}
\lipsum[4]
\section*{ \color{red} Recommendations:}
\lipsum[5]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}


I did a "less elegant" code where I included the figure in the body of the document (meaning after the \begin{document} and managed to align the figure with vspace, hspace. Although this solution works, I'm wondering if there is a way to do it as I stated at the beginning of this post. Below I post this "less elegant" code

\documentclass[a4paper]{article}

\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{showframe}

\definecolor{mygreen}{RGB}{112,173,71}
\definecolor{myblue}{RGB}{208,228,245}

\newcommand{\fph}{%Definition of first page header figure
\hspace{-4.5cm}
\begin{tikzpicture}
\draw[fill=mygreen,color=mygreen] (0,0) rectangle (21.6,9.5);
%Braces
\draw[rounded corners = 3pt, color=myblue, line width=3pt]
(6.0,5.25)..controls(5.72, 5.3)..(5.5,5.5) -- (5.5,7.5)..controls(5.72, 7.7)..(6.0,7.75);
\draw[rounded corners = 3pt, color=myblue, line width=3pt]
(11.0,5.25)..controls(11.28,5.3)..(11.5,5.5) -- (11.5,7.5)..controls(11.28,7.7)..(11.0,7.75);
%White Line:
\draw[color=white, line width=4pt] (0.0,4.5)--(21.6,4.5);
%Document Information:
\draw(8.5,6.5) node[color=myblue] { \huge{ \textbf{ Example Title } } };
\draw(2.35,3.8) node[anchor=west, color=myblue]{\large{\textbf{Authors:}}};
\draw(2.31,3.0) node[anchor=west, color=myblue]{\large{ Mr. B., Mrs. A., Dr. C. }};
%
\draw(14.5,2.4) node[anchor=west, color=myblue]{\large{\textbf{Date:} }};
\draw(17,2.4) node[anchor=west, color=myblue]{\large{13-Mar-2013 }};
%
\draw(14.5,1.0) node[anchor=west, color=myblue]{\large{\textbf{LaTeX Document}}};
\end{tikzpicture}%
}

\fancypagestyle{my1stpagestyle}{
\fancyfoot[C]{First page footer}
}

\fancypagestyle{generalpagestyle}{
\fancyfoot[C]{test running footer}
}

\pagestyle{generalpagestyle}

\begin{document}
\thispagestyle{my1stpagestyle}
\vspace*{-5.1cm}
$\fph$

\LARGE{\bf \color{red} Report Summary }\\
\lipsum[1-2]
\section*{ \color{red} Main findings:}
\lipsum[4-5]
\section*{ \color{red} Recommendations:}
\lipsum[6]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}


If I compile this, it returns the desired result:

• For one page, fancyhdr is NOT the way to go. It will increase \headheight to match the contents. – John Kormylo Jul 27 '19 at 3:22

Welcome to TeX.SE!

You can include the tikzpicture at the beginning of the document using the overlay option to ensure it doesn't take any space. From there, it can be appropriately shifted so that (for instance) the top-left corner of the green rectangle coincides with the top-left corner of the page. The code would be a bit more natural if you had given coordinate (0,0) to the point wanted at the top-left corner of the page (because of this, I have to use one of your rectangle dimensions in my yshift, namely 9.5cm).

\documentclass[a4paper]{article}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{showframe}

\definecolor{mygreen}{RGB}{112,173,71}
\definecolor{myblue}{RGB}{208,228,245}

\newcommand{\fph}{% Definition of first page figure
\begin{tikzpicture}[
overlay, xshift=-\oddsidemargin-1in,
\draw[fill=mygreen,color=mygreen] (0,0) rectangle (21.6,9.5);
%Braces
\draw[rounded corners = 3pt, color=myblue, line width=3pt]
(6.0,5.25)..controls(5.72, 5.3)..(5.5,5.5) -- (5.5,7.5)..controls(5.72, 7.7)..(6.0,7.75);
\draw[rounded corners = 3pt, color=myblue, line width=3pt]
(11.0,5.25)..controls(11.28,5.3)..(11.5,5.5) -- (11.5,7.5)..controls(11.28,7.7)..(11.0,7.75);
%White Line:
\draw[color=white, line width=4pt] (0.0,4.5)--(21.6,4.5);
%Document Information:
\draw(8.5,6.5) node[color=myblue] { \huge{ \textbf{ Example Title } } };
\draw(2.35,3.8) node[anchor=west, color=myblue]{\large{\textbf{Authors:}}};
\draw(2.31,3.0) node[anchor=west, color=myblue]{\large{ Mr. B., Mrs. A., Dr. C. }};
%
\draw(14.5,2.4) node[anchor=west, color=myblue]{\large{\textbf{Date:} }};
\draw(17,2.4) node[anchor=west, color=myblue]{\large{13-Mar-2013 }};
%
\draw(14.5,1.0) node[anchor=west, color=myblue]{\large{\textbf{LaTeX Document}}};
\end{tikzpicture}%
}

\fancypagestyle{my1stpagestyle}{%
\fancyfoot[C]{First page footer}
}

\fancypagestyle{generalpagestyle}{%
\fancyfoot[C]{test running footer}
}

\pagestyle{generalpagestyle}

\begin{document}

\thispagestyle{my1stpagestyle}
\noindent\fph               % this takes no space

\vspace*{5cm}               % or whatever
\noindent
\LARGE{\bf \color{red} Report Summary }\\
\lipsum[1-2]
\section*{Main findings}
\lipsum[4-5]
\section*{Recommendations}
\lipsum[6]

\end{document}


Another possibility would be to use the options remember picture and overlay in the tikzpicture, declare a coordinate like:

\coordinate (top left) at (current page.north west);


and place all other elements of your figure relatively to this (top left) point. Because of the remember picture option, this method requires two compilation runs, though.

By the way, why did you put \fph (i.e., the tikzpicture) inside a math display? Was it an attempt to center it horizontally? There is \centering for this purpose (sometimes, one can also do that with two \hspace*{\fill}).

• Hello @frougon. Thank you for reply. I used the math display because when I didn't, it was indenting the picture (placing it a bit to the right). I will remove it. Although your answer gives a possible solution, I was wondering if there is a way to include the figure in the preamble, and not in the document. This is the first step I want to achieve, before attempting to place the figure definition in a .cls file that I would like to define at a later stage. – CA-LaTeX Jul 29 '19 at 6:10
• The indent you mentioned was probably \parindent (use \noindent when you don't want it). The picture is already defined in the preamble in my answer. It can't be in the preamble outside a command definition, that would be illegal—document contents can't be output directly before \begin{document}. – frougon Jul 29 '19 at 7:33
• Sorry. I'm quite new at this. I will accept it. Thanks! :-) – CA-LaTeX Aug 4 '19 at 18:03