【问题标题】:How to edit footer in RMarkdown using the fancyhdr package如何使用 fancyhdr 包在 RMarkdown 中编辑页脚
【发布时间】:2020-07-17 23:00:56
【问题描述】:

我在 RMarkdown 中使用 LaTeX 中的 fancyhdr 包创建了一个 PDF。我正在尝试找到一个解决方案,在该解决方案中,我可以插入一条水平线作为页脚(就在页码上方),以及类似于我所附图像的右上角的页码。另外,有没有一种方法可以将所有超链接(例如目录)的颜色从默认的黑色更改为与图像相同的颜色?

我的 YAML 如下

---
title: "Template for a Dynamic Report for Work"
Uni_Logo: Tex/logo.jpg
Author1: "Tangeni Shatiwa" 
# ----- Manage headers and footers:
#BottomLFooter: $Title$
#BottomCFooter:
#TopLHeader: \leftmark # Adds section name at topleft. Remove comment to add it.
BottomRFooter: "\\footnotesize Page \\thepage" # Add a '#' before this line to remove footer.
addtoprule: TRUE
addfootrule: TRUE               # Use if footers added. Add '#' to remove line.
toc: TRUE
numbersections: TRUE             # Should sections (and thus figures and tables) be numbered?
fontsize: 11pt                  # Set fontsize
linestretch: 1.2                # Set distance between lines.
link-citations: TRUE   # This creates dynamic links to the papers in reference list.
linkcolor: blue
output:
  pdf_document:
    includes:
      in_header: "header.tex"
---

header.tex文件内容如下

\usepackage{fancyhdr}
\usepackage{titling}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\setlength{\headheight}{50pt}
\lhead{\includegraphics[width = .2\textwidth]{logo.jpg}}
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0pt}

\pretitle{%
  \begin{center}
  \LARGE
  \includegraphics[width=4cm,height=6cm]{logo.jpg}\\[\bigskipamount]
}
\posttitle{\end{center}}

TIA!

【问题讨论】:

    标签: r r-markdown


    【解决方案1】:

    这是一个示例 rmarkdown 文档和 header.tex 文件。我删除了header.tex 中的徽标行,因为我没有您的徽标。让我知道这是否是您的想法。

    rmarkdown文件

    ---
    title: "Template for a Dynamic Report for Work"
    Author1: "Tangeni Shatiwa" 
    BottomRFooter: "\\footnotesize Page \\thepage" # Add a '#' before this line to remove footer.
    addtoprule: TRUE
    addfootrule: TRUE               # Use if footers added. Add '#' to remove line.
    toc: TRUE
    numbersections: TRUE             # Should sections (and thus figures and tables) be numbered?
    fontsize: 11pt                  # Set fontsize
    linestretch: 1.2                # Set distance between lines.
    link-citations: TRUE   # This creates dynamic links to the papers in reference list.
    urlcolor: darkred
    output:
      pdf_document:
        includes:
          in_header: "header.tex"
    ---
    
    \newpage
    \pagenumbering{arabic} 
    
    Some text
    
    [This is a link to Stack Overflow](www.stackoverflow.com)
    
    Some more text
    
    \newpage
    
    Even more text
    ---
    
    \newpage
    \pagenumbering{arabic} 
    
    Some text
    
    [This is a link to Stack Overflow](www.stackoverflow.com)
    
    Some more text
    
    \newpage
    
    Even more text
    

    header.tex文件

    \usepackage{fancyhdr}
    \usepackage{titling}
    \pagestyle{fancy}
    \fancyhead{}
    \fancyfoot[L]{This is the left footer}
    \fancyfoot[R]{\thepage}
    \fancyfoot[C]{}
    \setlength{\headheight}{50pt}
    %\lhead{\includegraphics[width = .2\textwidth]{logo.jpg}}
    \renewcommand{\footrulewidth}{1pt}
    \pretitle{%
      \begin{center}
      \LARGE
      %\includegraphics[width=4cm,height=6cm]{logo.jpg}\\[\bigskipamount]
    }
    \posttitle{\end{center}}
    \pagenumbering{gobble}
    \usepackage{xcolor}
    \definecolor{darkred}{rgb}{0.7,0,0}
    

    PDF 输出

    【讨论】:

    • 是的,这就是我想要的,谢谢@eipi10!有什么办法可以在每个页码前加上“page”这个词吗?
    猜你喜欢
    • 1970-01-01
    • 2019-06-05
    • 2018-11-06
    • 1970-01-01
    • 2017-10-26
    • 2015-08-24
    • 1970-01-01
    • 2020-01-08
    • 2015-07-14
    相关资源
    最近更新 更多