tags:

views:

62

answers:

2

Dear all,

I am generating an automatically generated periodical report with Sweave. In order to create a nice header I use the fancyhdr package which works really well so far. Now, since my report is periodical I want to change the header dynamically without passing an argument to the function. That's why I wrote a little R function that just checks which period is the latest. Based on this a Header String is generated in R.

Long story short, I know that there is \today in LaTeX but I need to use the specific information coming from R, not just the date.

Here's my code:

   \usepackage{fancyhdr}
 \pagestyle{fancy}

\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\rightmark{
<<>>=
print(TexHeader)@
}}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt}
\fancypagestyle{plain}{%
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}}

which causes the following error:

Package Fancyhdr Warning: \fancyhead's `E' option without twoside option is use
less on input line 23.

This is exactly the line where my TexHeader is placed. Thx in advance for any suggestions!

+1  A: 

This is just a warning, not an error. The warning regards the fact that you have added formatting for your even pages, which is only relevant if you are using double sided output, activated using the 'twoside' option in your document class. otherwise all pages are treated as odd by fancyhdr

second
Thanks, you were right. It was not the error that really caused the problem.
ran2
+1  A: 

For one-sided documents you can use \fancyhead[L]{...} and \fancyhead[R]{...}.

Furthermore, in this case, it's better to use <<results=tex, echo=FALSE>>=. Here's an example:

\documentclass[a4paper]{report}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[R]{\bfseries\thepage}
\fancyhead[L]{\rightmark{%
<<results=tex, echo=FALSE>>=
TexHeader <- format(Sys.time(), "%c")
cat(TexHeader)
@
}}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt}
\fancypagestyle{plain}{%
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}}

\begin{document}
\lipsum
\end{document}
rcs
Eh, TexHeader returns a String in my case. Just did not get this string from R to the pdf...
ran2
This just an example, `TeXHeader` is also a string here which could be replaced by any other string in the global enviromnent.
rcs
Sorry the noise everybody. Again I had an encoding problem with my document because [expletive] [expletive] TeXShop encoded the document in Mac OS Roman. anyway +1 helping to improve my code !
ran2