How to underline in a Rmarkdown inline code?

Viewed 94

I am trying to create a report based on a shiny app, and I would like to underline some of the text of the report.

Here is a simple example to illustrate my problem:

[![---
title: "Untitled"
output:
  pdf_document: default
  html_document: default
date: '2022-07-18'
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown


```{r}
toPrint <- NULL

toSAve <- list(c("banana", "yellow"), c("apple", "green"))

  for(i in 1:length(toSAve)){
        toPrint <- paste(toPrint, paste0(i, ".", toSAve\[\[i\]\]\[1\],"\\linebreak"), toSAve\[\[i\]\]\[2\], "\\linebreak", "\\linebreak")
  }
```

\raggedright
`r toPrint`][1]][1]

enter image description here

In this report, I would like to underline the name of the fruits? Banana and Apple should be underlined. Is there a way to do that ? or the fact to have everything in a inline code makes it impossible ?

1 Answers

There isn't really any syntax for underlined text, but R Markdown will render spans with class .ul as underlined:

[this is underlined]{.ul}

So in your example, we'd write the below to underline the fruits:

toPrint <- NULL

toSAve <- list(c("banana", "yellow"), c("apple", "green"))

for(i in 1:length(toSAve)){
  toPrint <- paste(
    toPrint,
    paste0(i, ". ", "[", toSAve[[i]][1], "]{.ul}", "\\\n",
           toSAve[[i]][2], "\n\n")
  )
}

Note also the use of "\\\n" – a backslash followed by a linebreak – to mark the linebreak, as this will work with both PDF and HTML output.

Related