[Tex/LaTex] How to align header/footer

fancyhdrheader-footerpositioning

I want to get left border of the header, please see below, to the tip of the section title and the right border to the end of the text. I use fancyhdr package and the code is:

\documentclass[10pt]{article}
\usepackage{calc}
\usepackage{graphicx}
\usepackage{caption}

\makeatletter
\newlength{\bibhang}
\setlength{\bibhang}{1em}
\newlength{\bibsep}
 {\@listi \global\bibsep\itemsep \global\advance\bibsep by\parsep}
\newenvironment{bibsection}%
        {\vspace{-\baselineskip}\begin{list}{}{%
       \setlength{\leftmargin}{\bibhang}%
       \setlength{\itemindent}{-\leftmargin}%
       \setlength{\itemsep}{\bibsep}%
       \setlength{\parsep}{\z@}%
        \setlength{\partopsep}{0pt}%
        \setlength{\topsep}{0pt}}}
        {\end{list}\vspace{-.6\baselineskip}}
\makeatother

\reversemarginpar

\usepackage[paper=a4paper,
            %includefoot, % Uncomment to put page number above margin
            marginparwidth=25mm,    % Length of section titles
            marginparsep=1.5mm,       % Space between titles and text
            margin=25mm,              % 25mm margins
            includemp]{geometry}

\usepackage{paralist}
\setlength{\parindent}{0in}



\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyfootoffset{.2\textwidth}%\marginparsep+\marginparwidth
\fancyheadoffset{20pt}
\lhead{The Curiculum Vitae of Vahid Ebrahimzade}
\rhead{\thepage}
\chead{}
\fancyfoot{}

\usepackage{color,hyperref}
\definecolor{darkblue}{rgb}{0.0,0.0,0.3}
\hypersetup{colorlinks,breaklinks,
            linkcolor=blue,urlcolor=blue,
            anchorcolor=blue,citecolor=kblue}

\renewcommand{\section}[2]%
        {\pagebreak[2]\vspace{1.3\baselineskip}%
         \phantomsection\addcontentsline{toc}{section}{#1}%
         \hspace{0in}%
         \marginpar{
         \raggedright \scshape #1}#2}


\newenvironment{innerlist}[1][\enskip\textbullet]%
        {\begin{compactitem}[#1]}{\end{compactitem}}

\newcommand{\blankline}{\quad\pagebreak[2]}

\begin{document}

\section{Forschungs-\newline t\"atigkeit}
%\vspace{.5cm}
\begin{bibsection}
\item Modellreduktion Methoden
\item Surrogate Modellierung; Polynomfunktion Methoden, Radiale Basisfunktion Methoden
\end{bibsection}

\vspace{2cm}        

\end{document}      

Which leads to:
enter image description here

Can anyone help me?

Best Answer

Your header needs an offset to the left equal to the width of the space reserved for marginal notes (\marginparwidth) plus the separation between marginal notes and the text body (\marginparsep), like so

\fancyheadoffset[L]{\dimexpr\marginparsep+\marginparwidth}

A complete example:

\documentclass[10pt]{article}
\usepackage{calc}
\usepackage{graphicx}
\usepackage{caption}

\makeatletter
\newlength{\bibhang}
\setlength{\bibhang}{1em}
\newlength{\bibsep}
 {\@listi \global\bibsep\itemsep \global\advance\bibsep by\parsep}
\newenvironment{bibsection}%
        {\vspace{-\baselineskip}\begin{list}{}{%
       \setlength{\leftmargin}{\bibhang}%
       \setlength{\itemindent}{-\leftmargin}%
       \setlength{\itemsep}{\bibsep}%
       \setlength{\parsep}{\z@}%
        \setlength{\partopsep}{0pt}%
        \setlength{\topsep}{0pt}}}
        {\end{list}\vspace{-.6\baselineskip}}
\makeatother

\reversemarginpar

\usepackage[paper=a4paper,
            %includefoot, % Uncomment to put page number above margin
            marginparwidth=25mm,    % Length of section titles
            marginparsep=1.5mm,       % Space between titles and text
            margin=25mm,              % 25mm margins
            includemp]{geometry}

\usepackage{paralist}
\setlength{\parindent}{0in}



\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyheadoffset[L]{\dimexpr\marginparsep+\marginparwidth}
\fancyfootoffset{.2\textwidth}%\marginparsep+\marginparwidth
\lhead{The Curiculum Vitae of Vahid Ebrahimzade}
\rhead{\thepage}
\chead{}
\fancyfoot{}

\usepackage{color,hyperref}
\definecolor{darkblue}{rgb}{0.0,0.0,0.3}
\hypersetup{colorlinks,breaklinks,
            linkcolor=blue,urlcolor=blue,
            anchorcolor=blue,citecolor=kblue}

\renewcommand{\section}[2]%
        {\pagebreak[2]\vspace{1.3\baselineskip}%
         \phantomsection\addcontentsline{toc}{section}{#1}%
         \hspace{0in}%
         \marginpar{
         \raggedright \scshape #1}#2}

\newenvironment{innerlist}[1][\enskip\textbullet]%
        {\begin{compactitem}[#1]}{\end{compactitem}}

\newcommand{\blankline}{\quad\pagebreak[2]}

\begin{document}

\section{Forschungs-\newline t\"atigkeit}
%\vspace{.5cm}
\begin{bibsection}
\item Modellreduktion Methoden
\item Surrogate Modellierung; Polynomfunktion Methoden, Radiale Basisfunktion Methoden
\end{bibsection}

\vspace{2cm}        

\end{document}

enter image description here

As a side note, the \newline command in the argument of \section will pose you problems (with the bookmark, an eventual ToC entry). Were you using \section with a redefinition allowing the optional argument, this could've been easily solved.

Related Question