1

I am writing a class template for some documents and would like the \rhead{...} to be right aligned (as it normally is).

However with the setup i currently have, the header not on the far right; it is similar to the problem of this question, but I already set the page geometry before initializing the header.

\ProvidesClass{docu}[2020 v1.0 Documentation]
\LoadClass[11pt,a4paper,oneside,ngerman]{article}

\usepackage[showframe]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{fontspec}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{afterpage}
\usepackage{tikz}
\usepackage[dvipsnames]{xcolor}
\usepackage{tocloft}
\bibliographystyle{unsrtnat}

\geometry{ a4paper
         , portrait
         , top    = 4cm
         , bottom = 3.5cm
         , left   = 6cm
         , right  = 3cm }


\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont{Georgia}

\definecolor{maroon}{RGB}{116,25,16}
\newcommand{\titleBar}[1]{
    \tikzstyle{line} = [draw,thick, draw=maroon]
        \begin{tikzpicture}
            \path [line] (-2,0) -- (-2,0.5);
            \path [line] (-2,0.5) -- ({#1},0.5);
        \end{tikzpicture}
}

\newcommand{\abteilung}[1]{\def\@abteilung{#1}}
\abteilung{Abteilung}
\def\@abteilung{\@abteilung}

\newcommand{\version}[1]{\def\@version{#1}}
\version{DRAFT}
\def\@version{\@version}

\title{Hello, World!}
\author{Kurzzeichen}
\date{\today}

\pagestyle{fancy}
\fancyhf{}

\renewcommand{\headrulewidth}{0pt}


\makeatletter
\renewcommand{\maketitle}{
    \rhead{}
    {\noindent\@abteilung}\\[4\baselineskip]

    \null\hspace{-1cm}\noindent{\titleBar{12cm}}
    {\huge\textbf{\textit{{\@title}}}}\\
    {\huge{Documentation}}\\[4\baselineskip]
    {\@date}\\[2\baselineskip]
    {\@version}
    \lfoot{\hspace{-3cm}\includegraphics[scale=0.25]{logo.jpg}}

    \newgeometry{ a4paper
                 , portrait
                 , top    = 3cm
                 , bottom = 3.5cm
                 , left   = 3cm
                 , right  = 3cm }

    \newpage

    \tableofcontents
    \newpage

    \pagestyle{fancy}
    \fancyhf{}

    \renewcommand\headrule{
        \begin{minipage}{1\textwidth}
        \hspace{-0.51cm}\tikzstyle{line} = [draw,thick, draw=maroon]
        \begin{tikzpicture}
            \path [line] (-0.06,0.5) -- (-15.5,0.5);
            \path [line] (-15.5,0.5) -- (-15.5,0);
        \end{tikzpicture}
        % \hrule width \hsize \kern 1mm \hrule width \hsize height 2pt 
    \end{minipage}}%

    \fancyhead[R]{hi\\test}

    \lfoot{\@title\\Company}
    \rfoot{\@date\\\thepage}

}
\makeatother

I have enabled the frames to find the problem but was unable to do so until now: The right header as well as the footer are not aligned with the text itself although I create the fancyhdr after i initialize a new geometry.

what it looks like

Is this due to some kind of package conflict? How can I fix it?

my main.tex:

\documentclass{docu}
\usepackage{lipsum}

\begin{document}
\title{My Program Name}
\author{SCFA}
\date{31.01.2020}
\abteilung{Abteilung}
\version{Final Version}

\maketitle

\section{test section}
\lipsum[1-1]
\subsection{test subsection}
\lipsum\footnote{This is a test footnote}

\medskip

\end{document}
4
  • i added my main.tex; the first page has a different page size; (more left indent) the rest should have the standard 3.5cm from the left; Commented Feb 5, 2020 at 10:28
  • well the first geometry is used for the first page; then I set a new geometry for the table of contents and the rest of the document Commented Feb 5, 2020 at 11:09
  • isnt the \geometry at the top used for the title page and thereafter the newgeometry for the next pages? the titlepage corresponds to the geometry specified after the usepackages and the next pge (containing the toc) uses the geometry specified by the newgeometry; at least in the pdf compiled with xelatex in my machine Commented Feb 5, 2020 at 14:32
  • sorry I misread the code (it's somewhat unusual to have a multipage \maketitle :-) But my comments were wrong so i deleted them sorry. I'll trace what's happening this evening if no one answered by then, can't look now Commented Feb 5, 2020 at 14:35

1 Answer 1

2

You are not setting the geometry before initializing the headers. You have

\pagestyle{fancy}
\fancyhf{}

in two places in your code.

You can reset the headwidth after the \newgeometry by calling this command:

    \newgeometry{ %a4paper    %unused anyway
                  %, portrait %unused anyway
                 , top    = 3cm
                 , bottom = 3.5cm
                 , left   = 3cm
                 , right  = 3cm }
    \f@nch@setoffs
1
  • i deleted the second \pagestyle...cyhf{} now and added the command you mentioned; where can i find documentation on the \f@nch@setoffs command? Commented Feb 7, 2020 at 23:33

You must log in to answer this question.

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