我有这个降价文件:
当你运行它时,你会看到标题"#group B我的文字页面"和 "#group C我的文字页面"在文本中,#不被识别为标题。
但如果你取消注释
#plot(i, main = "first plot")
#plot(i*100,main = "second plot")
在创建这些页面的循环中,您将看到#被识别,标题应该是#34; B组是我的文本页面"和 " C组我的文字页面"两者都是粗体。
看来下面需要有一个情节:
cat("my text for page
...dslfjdlasjf kldsjf dsjafl djasklfj dasfjdasl jfdklsj fdklsaj dklsf")
使标题正常工作。为什么这样,以及如何修复,以便在
之下不需要绘图cat("my text for page
...dslfjdlasjf kldsjf dsjafl djasklfj dasfjdasl jfdklsj fdklsaj dklsf")
---
output:
pdf_document:
toc: yes
number_sections: false
pandoc_args: [
"-V","classoption=twocolumn"
]
keep_tex: TRUE
setspace: singlespacing
geometry: margin=1.1cm
fig.lp: 'Fig '
always_allow_html: yes
header-includes:
- \usepackage[usenames,table]{xcolor}
- \usepackage{amsmath}
- \usepackage{rotating}
- \usepackage{float}
- \usepackage{longtable}
- \usepackage{tabulary}
- \usepackage{array}
- \usepackage{colortbl}
- \usepackage{graphicx}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE , comment = NA, message= FALSE, warning = FALSE)
library(dplyr)
dat = data.frame(
group1 = sample( LETTERS , 500, TRUE ),
group2 = sample( LETTERS[1] , 500, TRUE ),
var1 = rnorm(500),
var2 = rnorm(500),
var3 = rnorm(500),
var4 = rnorm(500),
var5 = rnorm(500),
var6 = rnorm(500),
var7 = rnorm(500),
var8 = rnorm(500)
)
dat = dat %>% group_by(group1, group2) %>% summarise(s1 = sum(var1),
s2 = sum(var2),
s3 = sum(var3),
s4 = sum(var4),
s5 = sum(var5),
s6 = sum(var6),
s7 = sum(var7),
s8 = sum(var8)
) %>% as.data.frame()
rownames(dat) = NULL
groups = c("A","B","C")
class(groups)
```
```{r one, include= FALSE}
ta = data.frame(group = c("A,h","b, j "),`10-20`= c(1,"-"),`34-44`= c("-","-") ,check.names = FALSE)
ta
```
\newpage
# SUBJECT 1
my text for page
...dslfjdlasjf kldsjf dsjafl djasklfj dasfjdasl jfdklsj fdklsaj dklsf
```{r echo= FALSE, comment = FALSE, message= FALSE, warning = FALSE, results='asis'}
plot(4)
plot(66)
```
```{r echo= FALSE, comment = FALSE, message= FALSE, warning = FALSE, results='asis', fig.keep= 'all', fig.align='left'}
for(i in 1:length(groups)){
#cat(paste0("# SUBJECT ",i) )
cat(paste0("\\newpage\n # group ",groups[i], "\n"))
cat("my text for page
...dslfjdlasjf kldsjf dsjafl djasklfj dasfjdasl jfdklsj fdklsaj dklsf")
#plot(i, main = "first plot")
#plot(i*100,main = "second plot")
cat("\\newpage")
}
```
\newpage
```{r echo= FALSE, comment = FALSE, message= FALSE, warning = FALSE, results='asis'}
library(xtable)
options(xtable.include.rownames=F)
options(xtable.scalebox=.6)
options(xtable.tabular.environment = "tabulary")
options(xtable.width = "11 in")
options(xtable.comment=F)
options(xtable.floating = F)
#options("xtable.latex.environments", c("center"))
t = xtable(dat)
align(t) = "r|p{1cm}|p{1cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|"
digits(t) = c(0,0,0,1,1,1,1,1,1,1,1)
print(t, sanitize.text.function = identity,hline.after = c(-1,seq(0,nrow(t))) )
```
答案 0 :(得分:0)
这对我有用,在行的开头和结尾处都带有“ \ n \ n”,因此:
cat("\n\n# Test Heading\n\n")