Rmd编译为PDF时副标题与正文混排问题咨询
这问题我之前也碰到过!核心原因是Markdown里的**软换行(两个空格结尾)**在HTML渲染里能正常识别,但PDF输出是靠LaTeX引擎处理的,LaTeX根本不认这种换行方式,所以就把所有内容都挤成一团了。给你几个靠谱的解决办法:
1. 用硬换行(空一行)分隔内容
把副标题、正文、代码块之间都空出一行,这是最稳妥的方式,HTML和PDF都会正确解析分段。
2. 确保代码块格式正确
你原来的代码块开头少了反引号,正确的代码块应该用三个反引号包裹,不然LaTeX会把代码当成普通文本混在一起。
修正后的完整Rmd示例:
--- title: 'Script de Limpieza: errores de digitalizacion y division de base madre' author: "Leonardo Doig & Karen Lau" date: "10/9/2020" output: html_document: default word_document: default pdf_document: default --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)
some random words should be here
First subtitle
there are 2 blank spaces after the first subtitle
library(lubridate)
Second Subtitle
plain text (after the second subtitle there are 2 blanks spaces too)
### 额外小技巧 如果偶尔需要强制换行但不想分段,可以在换行处加`\\`(LaTeX的换行命令),比如: ```markdown #### First subtitle\\ there are 2 blank spaces after the first subtitle
不过还是更推荐空一行的方式,排版逻辑更清晰。
内容的提问来源于stack exchange,提问作者Karen Lau




