4

I'm currently writing a latex code generator to make invoices and I have a problem with my headers. I'm using fancy headers to make my headers and I'm using the output of the compiler to set the height of the header and the text. My problem is that my header is not at the same position on the first and the second page. It is higher on the first page and I don't find any solution to this problem.

Here is the code :

\documentclass[a4paper]{article}                                                                     
% setting language                                                                          
\usepackage[frenchb]{babel}                                                                 

% geometry --> margin ++                                                                    
\usepackage[includeheadfoot]{geometry}                                                                       
\geometry{a4paper,margin=1cm}                          

\usepackage{tabularx}                                                                                                                                                
\usepackage{booktabs}                                                                       

%\usepackage[absolute,overlay]{textpos}                                                     

\usepackage{fancyhdr}                                                                       
\pagestyle{fancy}                                                                                                                                                                                          
\renewcommand{\headrulewidth}{0pt}                                                          
\renewcommand{\footrulewidth}{0.4pt}                                                        
\newcommand\VRule[1][\arrayrulewidth]{\vrule width #1}                                                                                                                                                  

\usepackage{lipsum}                                                                     

\fancyhead[L]{
   \renewcommand{\arraystretch}{1}
   \raisebox{0\height}{                                                                     
    \begin{tabular}{p{4.99cm}l}                                                             
         Left part                                          
        &                                                                                   
         Right part       
        \\                                                                                  
    \end{tabular}                                                                           
}}                                                                                          
\fancyhead[R]{ \vtop{\begin{tabular}{l} \textbf{Devis n° 5}\\\textbf{Original}\\Page  \end{tabular}}}                                                           
\fancyfoot[C]{\textbf{Masidaso Consulting - N° TVA :BE0834757576}\\}                        

\setlength{\headheight}{64pt}

% début du corps                                                                            
\begin{document} 

\parskip=0pt\parindent=0pt                                                                  

        \renewcommand{\arraystretch}{1.4}                                                   

        \begin{tabularx}{\linewidth}{!{\VRule[2pt]}X!{\VRule[2pt]}X!{\VRule[2pt]}X!{\VRule[2pt]}}  \specialrule{2pt}{0pt}{0pt} Client & Intelocuteur & Page \\   \specialrule{2pt}{0pt}{0pt} 2 - Minou Chat & Mr le vendeur & page \\  \specialrule{2pt}{0pt}{0pt} \end{tabularx}                                                                                  
         \lipsum                                                                                                                                       
        \lipsum                                                                                    
        \renewcommand{\arraystretch}{1}

\end{document}  
8
  • Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you.
    – N.N.
    Jan 13, 2012 at 15:18
  • try adding \thispagestyle{fancy} after \begin{document} but before anything else is set. Jan 13, 2012 at 15:28
  • Ok I wont thank people in advance next :-) You guys are quite fast! @barbara beeton : your solution does not work but the one given below does. Jan 13, 2012 at 16:47
  • This is a lot of code. Even though you already got an answer, it'd be nice if you could remove everything from the code that's not related to your problem to make it a so-called minimal working example (MWE), that people can copy and compile to reproduce your problem. This way, your problem becomes relevant for a wider audience. All the tables and font definitions have nothing to do with the headers. If you need filler text, you can use e.g. the lipsum package.
    – doncherry
    Jan 13, 2012 at 17:27
  • 1
    I've updated the code to remove what's not related to the problem. Nevertheless, I still need at least one table in the document section for the \renewcommand{\arraystretch}{X} to be relevant. I hope it's short enough. If there are other concerns, just tell me and I'll try to fix them :-) Jan 13, 2012 at 18:59

1 Answer 1

3

The problem is that you're changing \arraystretch in the middle of the document, and this is reflected in the typesetting of the headers. Add \renewcommand{\arraystretch}{1} in the fields \fancyhead where you use tabulars. However the definitions seem quite complicated; the following code seems simpler.

\fancyhead[L]{%
  \renewcommand{\arraystretch}{1}%
  \raisebox{\dimexpr-\height+\ht\strutbox}{%
    \includegraphics[keepaspectratio,width=4.99cm,height=1.23cm]{logo.png}}%
  \qquad
  \begin{tabular}[t]{l}
    \chancery{\textbf{\LARGE Masidaso Consulting}}\\
    E-mail :  \href{mailto:[email protected]}{[email protected]}\\
    Tel : 0486609929\\
    ligne \\ ligne \\ ligne \\ ligne \\ ligne
  \end{tabular}\hfill
  \begin{tabular}[t]{l}
    \textbf{Devis n° 5}\\
    \textbf{Original}\\
    Page \thepage{} / \pageref{LastPage}
  \end{tabular}}

For this header, fancyhdr reports a height of 102pt.

2
  • It works perfectly! Could you tell me how you get the height of the header with fancyhdr? For the moment I simply run the compiler and get the height from the warning in the log. Jan 13, 2012 at 17:11
  • @ThibaultDory The same method I used: I put no setting of \headheight and compiled. :)
    – egreg
    Jan 13, 2012 at 17:16

You must log in to answer this question.

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