1

I have a rather complex layout for a letter. It needs to have a certain part of a header on every page while another part should only be shown on the first page. The whole thing can be found here: MWE

\documentclass[12pt,a4paper]{article}
\usepackage[
top=9cm,
bottom=3.5cm,
head=220pt,
left=2cm, 
right=2cm]{geometry}

\usepackage[table]{xcolor}
\usepackage{fancyhdr}
\usepackage{microtype}
\usepackage[hidelinks]{hyperref}
\usepackage[german]{babel}
\usepackage{tabularx}
\usepackage{enumitem}
\usepackage{lastpage}
\usepackage{parskip}
\usepackage{eurosym}

%Color definition
\definecolor{light-gray}{gray}{0.6}

%Remove par indent
\setlength{\parindent}{0cm}

%----------- Defined Variables -------------------------
\def\adress{company, Street 1, 123 City}
\def\aname{other company}
\def\aadd{Some Person}
\def\astreet{Street 2}
\def\apostal{321 City}
\def\onr{2014001}
\def\cnr{10}
\def\subject{Some Subject}
%----------- End Defined Variables ---------------------

%Settings for fancy table
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

%Fancy Header stuff
\pagestyle{fancy}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}% default is 0pt
\renewcommand{\footrule}{\color{light-gray}{\hrule} \vspace{10pt}}

%Actual Header and Footer Layout
\newcommand{\baseheader}{\fontsize{14pt}{1em}\selectfont 
    \textbf{\textcolor{light-gray}{company}}
    \color{light-gray}{\hrule}
    \vspace{10pt}
    }

\newcommand{\rightheader}{
  \hfill
  \begin{minipage}[b]{.49\textwidth}
    \fontsize{10pt}{1em}\selectfont
    \begin{flushright}
     \textcolor{black}{
      \begin{tabular}{lr}
        \textbf{Some info:} & \\
        Date: & \today \\
        Some Number: & \onr \\          
        Other Number: & \cnr \\
        Page: & \thepage\ of \pageref{LastPage} \\
      \end{tabular} 
      }     
    \end{flushright}
  \end{minipage}  
}
\newsavebox{\eheaderbox}
\begin{lrbox}{\eheaderbox}%
  \begin{minipage}[t]{.5\textwidth}
    \begin{flushleft}        
      {        
        \fontsize{8pt}{1em}\selectfont 
        \color{light-gray}\underline{
        \textcolor{light-gray}{\adress}}
      }        
      \fontsize{12pt}{1em}\selectfont
      \begin{itemize}[noitemsep,leftmargin=0pt,topsep=0px]      
        \item[] \aname
        \item[] \aadd
        \item[] \astreet
        \item[] \apostal        
      \end{itemize}        
    \end{flushleft}
  \end{minipage}
  \rightheader
\end{lrbox}

\fancypagestyle{firststyle}
{
   \fancyhf{}
   \fancyhead[R]{  
   \baseheader
   \vspace*{1.8cm}
   \usebox{\eheaderbox}
}
}

\fancyhf{}
\fancyhead[R]{  
  \baseheader
  \vspace*{1.8cm}
  \rightheader
}

\fancyfoot[L]{
  \fontsize{10pt}{1em}\selectfont
  Account Data:\\
  Acountholder\\
  IBAN: 123\\
  BIC: YAYBIC\\
  Bank: Some Bank
}
\fancyfoot[C]{
  \begin{minipage}[t]{3cm}
  \fontsize{10pt}{1em}\selectfont
  \begin{flushleft}
    Postal:\\
    comp name\\
    Street 1\\
    123 City
  \end{flushleft}
  \end{minipage}
}
\fancyfoot[R]{
\begin{minipage}[t]{4.5cm}
  \fontsize{10pt}{1em}\selectfont
  \begin{flushleft}  
    Contact:\\
    \href{http://www.comp.com/}{www.comp.com}\\
    Phone: 987654321
  \end{flushleft}    
  \end{minipage}
}
%End Actual Header and Footer Layout

\begin{document}
\thispagestyle{firststyle}
\textbf{\subject}
\par
Yadda
\par
More Yadda

\newpage
Second Page Yadda
\end{document}

There are several problems with my approach, it seems. The most pressing one for me is the misplaced minipage on the left. I just can't figure out how to make both parts of my header align. Any ideas?

  • Welcome to TeX.SX! You should paste your MWE into your question, so it may be read by future visitors even when the external link no longer works. – Andrew Swann Nov 26 '14 at 13:00
  • Will do. I just thought it was rather long for a MWE. – Nessuno Nov 26 '14 at 13:25
  • Is this what you want: i.stack.imgur.com/i72X2.png – user11232 Nov 26 '14 at 13:27
  • Welcome, out of curiosity, why don't you use a class that was designed for letters? scrlttr2 comes to mind. It is full of features. – Johannes_B Nov 26 '14 at 13:32
  • Right now you are aligning a top with a bottom. – John Kormylo Nov 26 '14 at 14:01
1

It seems that it was a plain oversight on my side. As Harish Kumar and John Kormylo point out I just have to remove the [t] parameter in the minipage definition inside the lrbox.

[...]
\newsavebox{\eheaderbox}
  \begin{lrbox}{\eheaderbox}%
    \begin{minipage}{.5\textwidth} % remove HERE
    \begin{flushleft}
    [...]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.