0

I am writing a report that outputs to html with R markdown. In this report I'm adding excel tables and one of them has a column with a list.

Here is the example

---
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")

this is the html output

The problem that I was having is that this part of the table there is great inconsistency in the output, the first row it looks fine, but everything breaks afterwards. the first line always turns out fine, but the second and third break looks like an outdented bullet. My question is how to make the format of this column uniform. I have read the tables section of R Markdown: The Definitive Guide and couldn't find any answers here, and have read other similar questions and their answers here this example is the most similar to my question, but as he is using pander and trying to export to pdf and word.

I have tried various formats, from removing the numbers and creating all bullet points and still I get the same indentation formatting. If I remove all numbers and don't put any - or * at the start of each line rmarkdown just treats like one whole column inconsistently. When I do a dput I can see that the first 1.is but after that it gets inconsistent even when playing around with the \r\n and haven't had any luck.

Manny Ma
  • 93
  • 1
  • 1
  • 11

1 Answers1

0

As I came to find out lists within tables in R markdown is not an intuitive business, even though the very similar answer how to write bullet lists for pdf with pandoc but the output is different and does not apply to my question. This person then asked multi-level bullet lists problem is the output they are working on is for pdf with pandoc, and I'm outputting to HTML.

I found out with put that my breaks were with\r\n while others had \ \n and by removing the r this worked and playing with it I saw that depending on the space after the . that you can make indentations \ \n1.observation does not give an indentation while \ \n1. observation does. hope this helps someone as it took me a whole day to figure this out by myself! and if someone has any information how this works please let me know!

Manny Ma
  • 93
  • 1
  • 1
  • 11