【问题标题】:How to add coloring to PDF reports in rmarkdown?如何在 rmarkdown 中为 PDF 报告添加颜色?
【发布时间】:2021-06-17 11:54:34
【问题描述】:

如何在使用 rmarkdown 创建 PDF 报告时为文本的特定部分添加背景颜色。如下所示

我尝试过这样的事情,但它在乳胶中工作,但在 rmarkdown 中没有

\titleformat{\section}{\sffamily\Large\bfseries\rlap{\color{DarkGreen!90}\rule[-0.5ex]{\linewidth}{3ex}\vspace{-3ex}}\sffamily\Large\color{white}}{\thesection}{1em}{}

this is how it looks in latex

this is in rmarkdown

---
title: "Untitled"
output: pdf_document
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
- \usepackage[table, svgnames]{xcolor}
- \usepackage{titlesec}
- \usepackage{sectsty}
- \usepackage{xcolor, soul}  
- \sectionfont{\color{red}}
- \subsectionfont{\color{green}}
- \subsubsectionfont{\color{blue}}
- \titleformat{\section}{\sffamily\Large\bfseries\rlap{\color{DarkGreen!90}\rule[-0.5ex]{\linewidth}{3ex}\vspace{-3ex}}\sffamily\Large\color{white}}{\thesection}{1em}{}

---
\section{Highlights}
# Section

【问题讨论】:

标签: r latex r-markdown pdflatex


【解决方案1】:

两个问题:

  • rmarkdown 已经加载了 xcolor 而没有注意您需要的选项。作为一种解决方法,您可以通过将必要的选项传递给所有包来欺骗降价

  • sectsty 将破坏您通过titlesec 所做的所有更改。不要同时加载它们


---
title: "Untitled"
output: 
  pdf_document:
    keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
- \usepackage{titlesec}
- \usepackage{soul}  
- \titleformat{\section}{\sffamily\Large\bfseries\rlap{\color{DarkGreen!90}\rule[-1.5ex]{\linewidth}{3ex}\vspace{-3.5ex}}\sffamily\Large\color{white}}{\thesection}{1em}{}

---
\section{Highlights}
# Section

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-29
    • 2020-03-24
    • 1970-01-01
    • 2010-10-22
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多