R降价:Latex标头存在问题

R降价:Latex标头存在问题,latex,r-markdown,Latex,R Markdown,当我使用自定义.sty文件和fancyhdr包设置标题时,标题文本会自动格式化,并且文本取自.Rmd文件中定义的第一个标题,我无法覆盖此行为。例如,我有下面的R标记文件 --- output: pdf_document: includes: in_header: report.sty keep_tex: yes geometry: tmargin=2cm, bmargin=2.5cm classoption: a4paper --- \pagenumbering

当我使用自定义.sty文件和fancyhdr包设置标题时,标题文本会自动格式化,并且文本取自.Rmd文件中定义的第一个标题,我无法覆盖此行为。例如,我有下面的R标记文件

---
output:
  pdf_document:
    includes:
      in_header: report.sty
    keep_tex: yes
geometry: tmargin=2cm, bmargin=2.5cm
classoption: a4paper
---

\pagenumbering{gobble}

# Behavioural profile of your dog

blah... blah...

```{r echo}

  # Some R code here...

```
这是.sty文件:

%
% This file must be saved with UTF-8 encoding, otherwise pandoc will complain
% for instance about nordic characters.
%

\usepackage{palatino}
\renewcommand{\familydefault}{\sfdefault} % sans serif
\fontfamily{ppl}\selectfont
\usepackage{blindtext}
\usepackage{eso-pic, rotating, graphicx, calc}
\usepackage[nomessages]{fp}

% Code to add a vertical gray band in the inner margin :
\usepackage{eso-pic}
\definecolor{colorMarge}{RGB}{242,242,245}
\newlength{\distance}
\setlength{\distance}{0.0in} % 0.5in
\newlength{\rulethickness}
\setlength{\rulethickness}{0.3in} % 1pt
\newlength{\ruleheight}
\setlength{\ruleheight}{11in} % Longueur de la ligne
\newlength{\xoffset}
\newlength{\yoffset}
\setlength{\yoffset}{0.5\dimexpr\paperheight-\ruleheight}

\AddToShipoutPicture{%
        \ifodd\value{page}%
                \setlength{\xoffset}{\distance}%
        \else
                \setlength{\xoffset}{\dimexpr\paperwidth-\rulethickness-\distance}%
        \fi
        \AtPageLowerLeft{\put(\LenToUnit{\xoffset},\LenToUnit{\yoffset}){\color{colorMarge}\rule{\rulethickness}{\ruleheight}}}%
}

\newcommand{\sidewaysText}{R Development Core Team (2008). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org.}

%\newlength{\swtLen}
%\setlength{\swtLen}{\widthof{\sidewaysText}}
%\newlength{\swtPos}
%\setlength{\swtPos}{\yoffset}
%\addtolength{\swtPos}{0.5\swtLen}

%\newlength{\swtPos}
%\setlength{\swtPos}{350em}

\AddToShipoutPicture{\put(5,10){\rotatebox{90}{\scalebox{0.8}{\sidewaysText}}}}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\chead{I want this header}
\lfoot{\scriptsize
Here is some footer text.}
但这就是结果:

如您所见,“THIS IS SOME HEADER”(这是一些标题)以大写字母、斜体和向右对齐显示为标题的一部分。如何避免这种情况

提前谢谢

加载到
report.sty
后,首先使用
\fancyhf{}
清除所有页眉/页脚。就是

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0.4pt}% Header rule
\renewcommand{\footrulewidth}{0.4pt}% Footer rule
\chead{I want this header}% Centre header
\lfoot{\scriptsize Here is some footer text.}% Left footer
您只设置了
\chead
\lfoot
,因此页眉/页脚的其他四个组件(每个组件三个:
l
eft、
c
entre、
r
ight)可能仍然包含内容规范。。。不管是什么
\fancyhf{}
清除所有这些,以便您可以根据需要进行设置


当然,如果您只想清除
r
ight
head
er,您也可以执行
\rhead{}

嗨,谢谢!很抱歉延迟回复。“它工作得很好。”沃纳感谢您的回复。如何在页眉下方的页面正文中抑制“This is Some Header”(这是某个页眉)。如果您只想在页眉而不是正文中显示章节标题。@user3022875:使用
#这是一些页眉
在LaTeX中设置一个
\section
\section
还调用
\sectiomark
,它在标题中设置一个“标记”。默认情况下,这是通过名为
\leftmark
的宏完成的。您可以通过向
report.sty
添加以下代码行来取消
\sectionmark
正在执行的操作:
\AtBeginDocument{\renewcommand{\sectionmark}[1]{}
@Werner感谢您的回复。你能看到我的例子吗:\AtBegin。。。仍然在体内保留指纹