HTML 输出的 R 降价列表中的表格缩进

Indentations in tables with lists in R markdown for HTML outputs

我正在写一份报告,输出到 html,带有 R markdown。在这份报告中,我添加了 excel tables,其中一个有一个包含列表的列。

示例如下

---
title: "Readme report"
author: "MM"
date: "`r Sys.Date()`"
output:  
  html_document:
    toc: true
    toc_float: true 
    number_sections: true
---
library(dplyr)
library(kableExtra)

df <- structure(list(id = c(1, 2, 3), justification = c(
"1. I want it too look like this \r\n 2. having numbers for each row \r\n 3. and well it still looks nice", 
"1. here is where strangeness happens\r\n 2. what happens here \r\n 3. and here", 
"1. but then I do this again and number one looks okay \r\n 2. but this looks like an outdented bullet \r\n   - i put this indented bullet \r\n 3.  and somehow end up like this when i get back to numbered"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-3L))

kable(df, format = "html")%>% 
  kable_styling(latex_options="scale_down")

我遇到的问题是 table 的这一部分在输出中存在很大的不一致,第一行看起来不错,但之后一切都中断了。第一行总是很好,但第二个和第三个中断看起来像一颗子弹。我的问题是如何使该栏目的格式统一。我已经阅读了 R Markdown: The Definitive Guide and couldn't find any answers here, and have read other similar questions and their answers 的 tables 部分,这个例子与我的问题最相似,但是因为他正在使用 pander 并试图导出到 pdf 和 word。

我尝试了各种格式,从删除数字到创建所有项目符号点,但我仍然得到相同的缩进格式。如果我删除所有数字并且不在每一行的开头放置任何 - 或 * rmarkdown 就像对待一整列不一致一样。当我执行 dput 时,我可以看到第一个 1.is 但之后它变得不一致,即使在玩 \r\n 时也没有任何运气。

当我发现 R markdown 表格中的列表不是一个直观的业务时,即使答案非常相似 但输出不同并且不适用于我的问题。这个人接着问 问题是他们正在处理的输出是带有 pandoc 的 pdf,我正在输出到 HTML。

我发现 put 我的休息时间是 \r\n 而其他人 \ \n 并且通过删除 r 这有效并使用它我看到了根据可以缩进的 . 之后的 space \ \n1.observation 不会缩进,而 1. observation 会。希望这对某人有帮助,因为我花了一整天的时间自己解决这个问题!如果有人知道这是如何工作的,请告诉我!