在rmarkdown pdf文档的标题前放置表格

798qvoo8  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(107)

我希望在rmarkdown生成的pdf报告第一页的标题上方有一个表格:

---
title: "test"
output: pdf_document
date: '2023-01-03'
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)

Including Plots

You can also embed plots, for example:

plot(pressure)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.


我知道在`Latex`中可以使用以下代码:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{multicol,lipsum}
\title{test title }
\author{testUser}
\date{\today}

\begin{document}
\noindent
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
cell1 & cell2 & cell3 \
cell4 & cell5 & cell6 \
cell7 & cell8 & cell9 \
\hline
\end{tabular}
\end{center}

\begingroup
\let\newpage\relax
\maketitle
\endgroup
\end{document}


这样就可以了,但是在`rmarkdown`中我们不使用`\maketitle`命令!
lmyy7pcs

lmyy7pcs1#

如果你的特克斯分布是合理的最新,你可以使用钩:

---
title: "test"
output: 
  pdf_document:
    keep_tex: true
date: '2023-01-03'
header-includes:
  - \AddToHook{cmd/maketitle/before}{\begin{center}\begin{tabular}{ |c|c|c| }\hline cell1 & cell2 & cell3 \\ cell4 & cell5 & cell6 \\  cell7 & cell8 & cell9 \\  \hline \end{tabular}\end{center}\begingroup \let\newpage\relax}
  - \AddToHook{cmd/maketitle/after}{\endgroup}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)

Including Plots

You can also embed plots, for example:

plot(pressure)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.


![](https://i.stack.imgur.com/CmHkk.png)

相关问题