Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在fancyhdr中使用Sweave(R)代码?_R_Latex_Sweave - Fatal编程技术网

如何在fancyhdr中使用Sweave(R)代码?

如何在fancyhdr中使用Sweave(R)代码?,r,latex,sweave,R,Latex,Sweave,我正在使用Sweave生成自动生成的定期报告。为了创建一个好的标题,我使用了fancyhdr包,到目前为止它运行得非常好。现在,由于我的报告是周期性的,所以我希望动态更改标题,而不向函数传递参数。这就是为什么我写了一个小R函数,它只检查哪个周期是最晚的。 基于此,在R中生成一个头字符串 长话短说,我知道LaTeX中有\ today,但我需要使用来自R的特定信息,而不仅仅是日期 这是我的密码: \usepackage{fancyhdr} \pagestyle{fancy} \renewc

我正在使用Sweave生成自动生成的定期报告。为了创建一个好的标题,我使用了fancyhdr包,到目前为止它运行得非常好。现在,由于我的报告是周期性的,所以我希望动态更改标题,而不向函数传递参数。这就是为什么我写了一个小R函数,它只检查哪个周期是最晚的。 基于此,在R中生成一个头字符串

长话短说,我知道LaTeX中有\ today,但我需要使用来自R的特定信息,而不仅仅是日期

这是我的密码:

   \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}}

这正是我的TexHeader所在的行。

这只是一个警告,不是错误。此警告与您为偶数页添加了格式有关,这仅在您使用双面输出时才相关,并在文档类中使用“双面”选项激活。否则,fancyhdr会将所有页面视为奇数。对于单面文档,您可以使用
\fancyhead[L]{…}
\fancyhead[R]{…}

此外,在这种情况下,最好使用
=
。 下面是一个例子:

\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}
\documentclass[a4paper]{report}
\usepackage{fancyhdr}
\usepackage{lipsum}
\页面样式{fancy}
\更新命令{\chaptermark}[1]{%
\标记两个{1}{}
\更新命令{\sectionmark}[1]{%
\markright{\thesection\#1}
\fancyhf{}
\fancyhead[R]{\bfseries\thepage}
\fancyhead[L]{\rightmark{%
=

TexHeader呃,在我的例子中,TexHeader返回一个字符串。只是没有将这个字符串从R获取到pdf…这只是一个例子,
TexHeader
在这里也是一个字符串,它可以被全局环境中的任何其他字符串替换。对不起,所有人都听到了噪音。我的文档再次出现编码问题,因为[咒骂][咒骂]TeXShop用Mac OS Roman对文档进行编码。无论如何+1有助于改进我的代码!谢谢,你是对的。真正导致问题的不是错误。
\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}