markdown转为pdf文档---Rmarkdown

Typora可以输出Pdf,但是样式并不够好看,尤其是没有页码的概念,转化出的tex再编译,代码高亮方式也不太合适。
那么,Rmarkdown要更好一些。
只需要在md文件前填写一些记录,再改为rmd的后缀,用knit编译即可。
插入代码时,代码段使用```python ```不要使用大括号,那会在编译文档过程中运行代码。

---
title: "markdown2pdf"
output: 
  pdf_document: 
    toc: true
    toc_depth: 2
    
    fig_ 7
    fig_height: 6
    fig_caption: true
    
    df_print: kable
    
    highlight: tango
    latex_engine: xelatex
    citation_package: biblatex
    keep_tex: true
---

Rmarkdown使用中文

4月10日更新,为了让Rmarkdown使用中文。参考以下链接。
RStudio 中Knitr 输出中文的问题。 · Issue #889 · yihui/knitr
rstudio/rticles: LaTeX Journal Article Templates for R Markdown
在R Markdown文档中使用中文 - 简书
在Rstudio控制台中,输入

install.packages("rticles")

安装必要的包,接着对前面的记录做一些修改。
如下

---
title: "移动对象"
documentclass: ctexart
output:
  rticles::ctex:
    fig_caption: yes
    number_sections: yes
    toc: yes
  pdf_document: 
    
    fig_ 7
    fig_height: 6
    
    df_print: kable
    
    includes:
      header-includes:
        - usepackage{xeCJK}
    highlight: tango
    latex_engine: xelatex

    citation_package: biblatex
    keep_tex: true
---

即可

中文效果

中文

效果

目录
代码
代码2

GBoost = GradientBoostingRegressor(n_estimators=600, learning_rate=0.05,
                                   max_depth=4, max_features='auto',
                                   min_samples_leaf=15, min_samples_split=5, 
                                   loss='huber', random_state =5)

参考:谢益辉的Rmarkdown包文档。

原文地址:https://www.cnblogs.com/lingr7/p/12275877.html