如何通过 rmarkdown 在 PDF 中放置 table 或更精确地格式化 header 文本?
How to place a table in a PDF via rmarkdown or format the header text more precisely?
我希望下面的 RMarkdown 代码(在 post 的末尾)输出带有下面 header 选项之一的页面。主要问题是如何实现格式化,因为我知道如何获取日期和页码。
我用谷歌搜索将 table 放入 header,但没有找到任何内容。更精确地格式化数据也是一个选项(即 Header 选项 2),但我还没有找到任何关于如何执行此操作的信息。我尝试过格式化,但没有什么值得放在这里的,因为下面的 RMarkdown 代码中没有。
问题:是否可以实施以下选项之一?以及如何做到。
Header 选项 1:使用 Table 包括文本格式(如果可能,包括 :
字符,但这不是绝对必要的) .
Header 选项 2:没有 Table 的类似格式,或者它甚至可以有一个框。
创建多页示例 PDF 的代码这是我想修改 header 以包含 table 解决方案或只是没有 table.
的格式化解决方案
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
includes:
in_header: header.tex
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{Page \thepage\ of \pageref{LastPage}}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
---
\thispagestyle{fancy}
# Example R Rarkdown : Numbered Sections
## R Markdown
### Description
Some description text
\newpage
#### Details
Details go here.
\newpage
## Plots
Plots go here
\newpage
Last page
这是一种方式,毫无疑问还有其他方式...
- 创建新奇的header页面样式
- 定义 table 样式 header(并删除一些默认行为)
- 删除头部规则
- 出于某种原因,第一页不喜欢 header,所以在第一页上强制使用 header
\thispagestyle(...)
- 定义后续页面样式为tableheader.
根据需要编辑外观...
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 4
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \usepackage{array}
- \usepackage{lipsum}
---
\fancypagestyle{tableHeader}{
\fancyhf{}
\setlength\headheight{90pt}
\fancyhead[C]{
\centering{
\begin{minipage}{1.1\textwidth}
\renewcommand{\arraystretch}{2}
\begin{tabular}{|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|}
\hline
\multicolumn{4}{|c|}{\textbf{\LARGE{Title}}} \
\hline
\textbf{\Large{Field 1:}} & \textbf{\Large{Field 2:}} & \textbf{\Large{Date:}} & \textbf{\Large{Page:}}\
\textbf{\Large{Information}} & \textbf{\Large{Information}} & \textbf{\Large{`r Sys.Date()`}} & \textbf{\Large{{\thepage} of \pageref{LastPage}}}\
\hline
\end{tabular}
\end{minipage}
}}
}
\renewcommand{\headrulewidth}{0pt}
\thispagestyle{tableHeader}
\pagestyle{tableHeader}
# Section 1
\lipsum[3]
## sub section
\newpage
\lipsum[2]
我希望下面的 RMarkdown 代码(在 post 的末尾)输出带有下面 header 选项之一的页面。主要问题是如何实现格式化,因为我知道如何获取日期和页码。
我用谷歌搜索将 table 放入 header,但没有找到任何内容。更精确地格式化数据也是一个选项(即 Header 选项 2),但我还没有找到任何关于如何执行此操作的信息。我尝试过格式化,但没有什么值得放在这里的,因为下面的 RMarkdown 代码中没有。
问题:是否可以实施以下选项之一?以及如何做到。
Header 选项 1:使用 Table 包括文本格式(如果可能,包括 :
字符,但这不是绝对必要的) .
Header 选项 2:没有 Table 的类似格式,或者它甚至可以有一个框。
创建多页示例 PDF 的代码这是我想修改 header 以包含 table 解决方案或只是没有 table.
的格式化解决方案---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
includes:
in_header: header.tex
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{Page \thepage\ of \pageref{LastPage}}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
---
\thispagestyle{fancy}
# Example R Rarkdown : Numbered Sections
## R Markdown
### Description
Some description text
\newpage
#### Details
Details go here.
\newpage
## Plots
Plots go here
\newpage
Last page
这是一种方式,毫无疑问还有其他方式...
- 创建新奇的header页面样式
- 定义 table 样式 header(并删除一些默认行为)
- 删除头部规则
- 出于某种原因,第一页不喜欢 header,所以在第一页上强制使用 header
\thispagestyle(...)
- 定义后续页面样式为tableheader.
根据需要编辑外观...
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 4
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \usepackage{array}
- \usepackage{lipsum}
---
\fancypagestyle{tableHeader}{
\fancyhf{}
\setlength\headheight{90pt}
\fancyhead[C]{
\centering{
\begin{minipage}{1.1\textwidth}
\renewcommand{\arraystretch}{2}
\begin{tabular}{|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|}
\hline
\multicolumn{4}{|c|}{\textbf{\LARGE{Title}}} \
\hline
\textbf{\Large{Field 1:}} & \textbf{\Large{Field 2:}} & \textbf{\Large{Date:}} & \textbf{\Large{Page:}}\
\textbf{\Large{Information}} & \textbf{\Large{Information}} & \textbf{\Large{`r Sys.Date()`}} & \textbf{\Large{{\thepage} of \pageref{LastPage}}}\
\hline
\end{tabular}
\end{minipage}
}}
}
\renewcommand{\headrulewidth}{0pt}
\thispagestyle{tableHeader}
\pagestyle{tableHeader}
# Section 1
\lipsum[3]
## sub section
\newpage
\lipsum[2]