# How to position fancyhdr[R]?

I cant get the right header/footer on the right position. It should be positioned 3cm from right page end. How can i achieve that?

Sample Document:

\documentclass[12pt,a4paper]{scrartcl}

% includes (they are maybe currently not needed, but later)
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ngerman}
\usepackage{pageslts}
\usepackage[hyphens]{url}
\usepackage[colorlinks=false]{hyperref}
\usepackage{floatflt}
\usepackage{fancyhdr}
\usepackage{blindtext}
\pagestyle{fancy}

% Layout anpassen
\setlength{\hoffset}{0.46cm}
\setlength{\voffset}{-0.04cm}
\setlength{\marginparwidth}{0pt}
\setlength{\oddsidemargin}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\textwidth}{15cm}
\setlength{\topmargin}{0pt}
\setlength{\headsep}{17pt}
\setlength{\textheight}{227mm}
\setlength{\footskip}{29pt}

% Kopf/Fußzeile
\fancyhf{}
\fancyhead[R]{Rechts}
\fancyhead[L]{Links}
\fancyfoot[R]{Rechts}
\fancyfoot[L]{Links}
\renewcommand\headrule{\rule{\textwidth}{1pt}}
\renewcommand\footrule{\rule{\textwidth}{1pt}\\}

\pagenumbering{arabic}

\begin{document}
\section{Ein Titel}
\Blindtext
\end{document}

• Do yo mean 3 cm from the physical page end, or from the end of line? – Bernard Jan 4 '14 at 10:08
• Rather than playing with \hoffset and so on, it's better to use the geometry package, that makes it easier to specify the page parameters. For instance, in order to have equal 3cm margins at both sides, just textwidth=15cm is sufficient. – egreg Jan 4 '14 at 10:11
• Note also that fancyhdr is not recommended for usage with scrartcl and scrpage2 is probably better, in this case. – egreg Jan 4 '14 at 10:19
• – karlkoeller Jan 4 '14 at 10:44
• @egreg: i've tried using the geometry package, but it looked more wrong like my case (in combination with fancyhdr). But with the answer of karlkoeller it works fine. Do you have more documentation, or better: is there a central place for docs, where i can look first before asking? (please don't say google :), i've tried that) – michi.0x5d Jan 4 '14 at 13:37

## 1 Answer

The problem is that the rule is \textwidth long and the right headers and footers don't fit, since you've declared \textwidth to be 15cm.

Anyway, all these declarations

% Layout anpassen
\setlength{\hoffset}{0.46cm}
\setlength{\voffset}{-0.04cm}
\setlength{\marginparwidth}{0pt}
\setlength{\oddsidemargin}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\textwidth}{15cm}
\setlength{\topmargin}{0pt}
\setlength{\headsep}{17pt}
\setlength{\textheight}{227mm}
\setlength{\footskip}{29pt}


should not be made directly, but with the help of the geometry package or with the facilities provided by KOMA classes (see Chapter 2 of KOMA-script documentation), but I'll leave that to you.

The most important thing is that KOMA classes provide an own method to deal with headers and footers (see Chapter 5 of the documentation) through the scrpage2 package.

In the following MWE I've substituted all fancyhdr commands with the corresponding scrpage2 ones (old ones are commented):

\documentclass[12pt,a4paper]{scrartcl}

% includes (they are maybe currently not needed, but later)
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ngerman}
\usepackage{pageslts}
\usepackage[hyphens]{url}
\usepackage[colorlinks=false]{hyperref}
\usepackage{floatflt}
\usepackage{scrpage2}   % \usepackage{fancyhdr}
\usepackage{blindtext}
\pagestyle{scrheadings} % \pagestyle{fancy}

% Layout anpassen
\setlength{\hoffset}{0.46cm}
\setlength{\voffset}{-0.04cm}
\setlength{\marginparwidth}{0pt}
\setlength{\oddsidemargin}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\textwidth}{15cm}
\setlength{\topmargin}{0pt}
\setlength{\headsep}{17pt}
\setlength{\textheight}{227mm}
\setlength{\footskip}{29pt}

% Kopf/Fußzeile
\clearscrheadfoot    % \fancyhf{}
\ohead{Rechts}       % \fancyhead[R]{Rechts}
\ihead{Links}        % \fancyhead[L]{Links}
\ofoot{Rechts}       % \fancyfoot[R]{Rechts}
\ifoot{Links}        % \fancyfoot[L]{Links}
\setkomafont{pageheadfoot}{\normalfont}
\setheadsepline{1pt} % \renewcommand\headrule{\rule{\textwidth}{1pt}}
\setfootsepline{1pt} % \renewcommand\footrule{\rule{\textwidth}{1pt}\\}

\pagenumbering{arabic}

\begin{document}
\section{Ein Titel}
\Blindtext
\end{document}


and this is the result: