rmarkdown 的 PDF 输出中边距太宽
Margin too wide in PDF output of rmarkdown
我正在尝试更新 rmarkdown 的 pdf 输出的边距。
这是我的代码:
---
title: "Analysis Report "
date: "Last edited `r format(Sys.time(), '%B %d, %Y')`"
geometry: "left=2cm,right=2cm,top=2cm,bottom=2cm"
output:
pdf_document:
toc: true
pandoc_args: [
"--number-sections",
"--number-offset=1"
]
---
```{r setup, include=FALSE}
library(naniar)
library(flexdashboard)
library(ggplot2)
library(rsconnect)
library(leaflet)
library(table1)
library(shiny)
library(DT)
library(readr)
library(kableExtra)
library(flextable)
library(expss)
library(tidyverse)
library(knitr)
library(plotly)
library(magrittr)
dfTab <- structure(list(x = structure(1:4, .Label = c("No, they do not agree", "Yes, they agree", "Unable to contact participant", "Undecided"),
class = "factor"), Freq = c(1L, 7L, 0L, 0L), lab = c("1 (12.5%)", "7 (87.5%)", "0 (0%)", "0 (0%)")),
row.names = c("No, they do not agree", "Yes, they agree", "Unable to contact participant", "Undecided"
), class = "data.frame")
\```
\newpage
# Sample Graph
```{r, echo=FALSE,out.width='\textwidth', fig.height = 7, fig.align='center', out.height="80%",out.width="80%"}
plot <- ggplot(dfTab, aes(x=x, y=Freq, fill=x)) +
geom_bar(width = 1, size = 1, stat = "identity") +
geom_text(aes(label=lab), vjust = -1)+
theme_classic() +
theme(#axis.text.x = element_text(size = 12, colour = "black"),
axis.line.x = element_line(),
axis.ticks.x = element_line(),
#axis.text.y = element_blank(),
#axis.line.y = element_blank(),
#axis.ticks.y = element_blank(),
#axis.text=element_text(size=12),
axis.title=element_text(size=12,face="bold"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position="top",
legend.title = element_blank())+
#scale_x_discrete(labels = abbreviate)+
labs(title="This is the title of the graph", x="", y="Count")
plot
请注意,我在上面的代码中的 3 个刻度之前添加了“\”,以便 Whosebug 编辑器识别我的代码。
无论如何,输出文档看起来像这样
差距还是太大了。我的代码有问题吗?我读到我必须在 geometry: "left=2cm,right=2cm,top=2cm,bottom=2cm"
中声明边距大小,但它似乎不起作用。非常感谢任何帮助。
让我们尝试用我为您制作的这个简单示例来解决您的问题。
---
title: "test"
header-includes:
\usepackage{geometry}
\geometry{top=0.75in,left=3in,bottom=0.75in,right=0.80in}
output:
pdf_document
---
Is it work at your machine - yes or no? \
By me - it works! \
^_^ \
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 pressure, echo=FALSE}
plot(pressure)
```
它能在您的 PC 上正常运行吗?
我正在尝试更新 rmarkdown 的 pdf 输出的边距。
这是我的代码:
---
title: "Analysis Report "
date: "Last edited `r format(Sys.time(), '%B %d, %Y')`"
geometry: "left=2cm,right=2cm,top=2cm,bottom=2cm"
output:
pdf_document:
toc: true
pandoc_args: [
"--number-sections",
"--number-offset=1"
]
---
```{r setup, include=FALSE}
library(naniar)
library(flexdashboard)
library(ggplot2)
library(rsconnect)
library(leaflet)
library(table1)
library(shiny)
library(DT)
library(readr)
library(kableExtra)
library(flextable)
library(expss)
library(tidyverse)
library(knitr)
library(plotly)
library(magrittr)
dfTab <- structure(list(x = structure(1:4, .Label = c("No, they do not agree", "Yes, they agree", "Unable to contact participant", "Undecided"),
class = "factor"), Freq = c(1L, 7L, 0L, 0L), lab = c("1 (12.5%)", "7 (87.5%)", "0 (0%)", "0 (0%)")),
row.names = c("No, they do not agree", "Yes, they agree", "Unable to contact participant", "Undecided"
), class = "data.frame")
\```
\newpage
# Sample Graph
```{r, echo=FALSE,out.width='\textwidth', fig.height = 7, fig.align='center', out.height="80%",out.width="80%"}
plot <- ggplot(dfTab, aes(x=x, y=Freq, fill=x)) +
geom_bar(width = 1, size = 1, stat = "identity") +
geom_text(aes(label=lab), vjust = -1)+
theme_classic() +
theme(#axis.text.x = element_text(size = 12, colour = "black"),
axis.line.x = element_line(),
axis.ticks.x = element_line(),
#axis.text.y = element_blank(),
#axis.line.y = element_blank(),
#axis.ticks.y = element_blank(),
#axis.text=element_text(size=12),
axis.title=element_text(size=12,face="bold"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position="top",
legend.title = element_blank())+
#scale_x_discrete(labels = abbreviate)+
labs(title="This is the title of the graph", x="", y="Count")
plot
请注意,我在上面的代码中的 3 个刻度之前添加了“\”,以便 Whosebug 编辑器识别我的代码。
无论如何,输出文档看起来像这样
差距还是太大了。我的代码有问题吗?我读到我必须在 geometry: "left=2cm,right=2cm,top=2cm,bottom=2cm"
中声明边距大小,但它似乎不起作用。非常感谢任何帮助。
让我们尝试用我为您制作的这个简单示例来解决您的问题。
---
title: "test"
header-includes:
\usepackage{geometry}
\geometry{top=0.75in,left=3in,bottom=0.75in,right=0.80in}
output:
pdf_document
---
Is it work at your machine - yes or no? \
By me - it works! \
^_^ \
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 pressure, echo=FALSE}
plot(pressure)
```
它能在您的 PC 上正常运行吗?