努力处理 bookdown 的 PDF 输出
Struggling with PDF output of bookdown
我认为使用 bookdown 编写更长的 report/protocol 是个好主意,因为每个主题写一个文件比只写一个包含所有内容的 RMarkdown 文档更舒服。现在我面临着共享此文档的问题 - HTML 看起来最好(宽表被截断除外)但很难通过 e-mail 发送给主管。我也不指望任何人能够在他们的计算机上打开 ePub 格式,因此 PDF 将是最简单的选择。现在我的问题:
我的章节标题很长,这在 HTML 中无关紧要,但它们不适合 PDF 文档中的页面 headers。在 LaTeX 中我可以为它定义一个简短的标题,我也可以在 bookdown 中这样做吗?
我在代码块中使用 knitr::include_graphics()
包含图形文件,因此我通过块选项生成标题。对于某些数字,我无法避免在标题中使用下划线,但这在 LaTeX 中不起作用。有没有办法逃避实际有效的下划线(最好同时用于 HTML 和 PDF)?渲染后我的 LaTeX 输出看起来像这样:
\textbackslash{}begin\{figure\}
\includegraphics[width=0.6\linewidth,height=0.6\textheight]{figures/0165_HMMER} \textbackslash{}caption\{Output of HMMER for PA\_0165\}\label{fig:0165}
\textbackslash{}end\{figure\}
编辑
MWE 显示问题是下划线与 out.height
(或宽度)的百分比组合:
---
title: "MWE FigCap"
author: "LilithElina"
date: "19 Februar 2020"
output: pdf_document
---
```{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:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE, fig.cap="This is a nice figure caption", out.height='40%'}
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.
```{r pressure2, echo=FALSE, fig.cap="This is a not nice figure_caption", out.height='40%'}
plot(pressure)
```
关于较短的标题:pandoc
,用于 markdown 到 LaTeX 的转换,不提供 "shorter heading"。不过你可以自己做:
# Really long chaper heading
\markboth{\thechapter~short heading}{}
[...]
## Really long section heading
\markright{\thesection~short heading}
这假设文档 class 包含章节。
关于图形标题中的下划线:对我来说,它适用于 PDF 和 HTML 以转义下划线:
```{r pressure2, echo=FALSE, fig.cap="This is a not nice figure\_caption", out.height='40%'}
plot(pressure)
```
我认为使用 bookdown 编写更长的 report/protocol 是个好主意,因为每个主题写一个文件比只写一个包含所有内容的 RMarkdown 文档更舒服。现在我面临着共享此文档的问题 - HTML 看起来最好(宽表被截断除外)但很难通过 e-mail 发送给主管。我也不指望任何人能够在他们的计算机上打开 ePub 格式,因此 PDF 将是最简单的选择。现在我的问题:
我的章节标题很长,这在 HTML 中无关紧要,但它们不适合 PDF 文档中的页面 headers。在 LaTeX 中我可以为它定义一个简短的标题,我也可以在 bookdown 中这样做吗?
我在代码块中使用 knitr::include_graphics()
包含图形文件,因此我通过块选项生成标题。对于某些数字,我无法避免在标题中使用下划线,但这在 LaTeX 中不起作用。有没有办法逃避实际有效的下划线(最好同时用于 HTML 和 PDF)?渲染后我的 LaTeX 输出看起来像这样:
\textbackslash{}begin\{figure\}
\includegraphics[width=0.6\linewidth,height=0.6\textheight]{figures/0165_HMMER} \textbackslash{}caption\{Output of HMMER for PA\_0165\}\label{fig:0165}
\textbackslash{}end\{figure\}
编辑
MWE 显示问题是下划线与 out.height
(或宽度)的百分比组合:
---
title: "MWE FigCap"
author: "LilithElina"
date: "19 Februar 2020"
output: pdf_document
---
```{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:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE, fig.cap="This is a nice figure caption", out.height='40%'}
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.
```{r pressure2, echo=FALSE, fig.cap="This is a not nice figure_caption", out.height='40%'}
plot(pressure)
```
关于较短的标题:pandoc
,用于 markdown 到 LaTeX 的转换,不提供 "shorter heading"。不过你可以自己做:
# Really long chaper heading
\markboth{\thechapter~short heading}{}
[...]
## Really long section heading
\markright{\thesection~short heading}
这假设文档 class 包含章节。
关于图形标题中的下划线:对我来说,它适用于 PDF 和 HTML 以转义下划线:
```{r pressure2, echo=FALSE, fig.cap="This is a not nice figure\_caption", out.height='40%'}
plot(pressure)
```