I'm trying to create an ordered list with sub bullet in an rmarkdown file but anytime i knitr to a pdf, the sub bullet list does not work, it only works when I knitr to html. I used the code below:
Food list
----------
* Rice
* Vegetables
* Tomatoes
* Carrot
* Cabbage
------------
A nested list (i.e. a bullet list in this example) in a main list (i.e. an ordered list in this example) should be indented four spaces, as shown below.
By the way, you have to use the proper Pandoc notation for an ordered list (i.e. 1. ) to create an ordered list.
---
output:
html_document: default
pdf_document: default
---
Food list
---------
1. Rice
1. Vegetables
* Tomatoes
* Carrot
* Cabbage
1. Fish
```{r sessionInfo}
rmarkdown::pandoc_version() # 2.19.2 in my environment
packageVersion("knitr") # 1.39 in my environment
packageVersion("rmarkdown") # 2.14 in my environment
```
HTML output
PDF output
Related
I created my lecture notes in pdf format using RMarkdown but it has many subheaders. Because of this, I want to create two different table of contents: first table of contents with 1 depth, then table of contents in 4 depth respectively.
Adding both toc_depth: 1 and toc_depth: 4 did not work.
My YAML header:
---
title: "Lecture Notes"
author: "x"
output:
pdf_document:
highlight: tango
toc: true
toc_depth: 4 #depth table of contents
number_sections: true
documentclass: article
classoption: a4paper
fontsize: 12pt
geometry: "right=1cm, left=1cm, top=1cm, bottom=3cm"
---
As far as I am aware, I don't believe two Table of Contents is possible. One thing you can try is if you don't want a certain heading numbered, you can do
## Including Plots {-}
Which heads it has a header, but doesn't number it in the TOC. Here is the two output differences
without {-}
with {-}
These can be used in places like the Preface, about the authors, etc.
This is not a perfect solution (maybe some with more knowledge could automate this).
The solution works if the intermediate latex file is kept and a short table of contents is manually added using the shorttoc package.
Adding shortdoc:
...
\documentclass[
]{book}
\usepackage{shorttoc}
...
And than adding it between title and TOC:
\shorttableofcontents{〈title 〉}{〈depth 〉}
Due to different journal requirements, I need to frequently change certain text styles within Rmarkdown from one kind to another. For instance, here is an example Rmarkdown document.
---
title: "Changing format of Rmarkdown"
author: "Paul Hargarten"
date: "5/9/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an $\mathcal{R}$ Markdown document. Markdown is a simple formatting syntax for authoring **HTML**, **PDF**, and **MS Word* documents. For more details on using $\mathcal{R}$ Markdown see <http://rmarkdown.rstudio.com>. $\matcal{R}$ is based on $\mathcal{S}$.
When you click the `Knit` button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. Calculate a `summary` as follows:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example: `r plot(pressure)`.
Without searching for the exact phrase, suppose that I would like to find and replace the following items:
1. Change items in bold ** ... ** to italics _ ... _.
2. Change items that look like $\mathcal{ ... }$ to bold ** ... **.
3. Change special font `...`, except those that start with r, to \code{ ... }.
4. Add dollar signs to `r ... ` => $`r ... `$.
Is this possible to use regex to make these formatting style changes in
Rmarkdown? Thanks!
This is something that LaTeX is good at, but it will be harder with Markdown.
If you were entirely in LaTeX, you could define your own macros based on the uses for that markup. For example,
\newcommand{\booktitle}[1]{\textbf #1}
used for book titles as \booktitle{The Book}. If you wanted to switch book titles to italic, you'd just change that definition.
Doing this in R Markdown is possible, but you wouldn't be able to mark book titles using **. You could do it (you can embed LaTeX in R Markdown), but it's ugly. For example,
---
title: Using LaTeX
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\newcommand{\booktitle}[1]{\textbf{#1}}
This is \booktitle{The Book}.
Once you're doing this, you might as well switch to Sweave-like *.Rnw format, or all the way to LaTeX.
I am using captioner (https://cran.r-project.org/web/packages/captioner/vignettes/using_captioner.html) to create table captions in Rmarkdown - the main reason is because I am using huxtable for conditional formatting and exporting to word. This is the only I have found to have numbered captions.
I was trying to reference the captions but the caption number is not in sequential order when citing the captions but only if the table_nums(..., display="cite") is before the tables. I was trying to give the range of table numbers and it changed the number of the last table. I The number isn't changed if the r table_nums('third_cars_table',display = "cite") is put after the captions. Is there a way to make sure that table numbers remain in sequential order? I'd also be happy with a better solution for numbered captions.
Reproducible example:
---
title: "Untitled"
output: bookdown::word_document2
---
```{r setup, include=FALSE}
library(captioner)
library(huxtable)
library(knitr)
library(pander)
table_nums <- captioner(prefix = "Table")
fig_nums <- captioner(prefix = "Figure")
knitr::opts_chunk$set(echo = TRUE)
```
## Description of tables
I am trying to put a description of tables
and say that these results are shown table numbers ranging
from the first table (`r table_nums('first_cars_table',display = "cite")`)
to the last table (`r table_nums('third_cars_table',display = "cite")`)
```{r, results='asis',echo=FALSE,eval.after=TRUE}
tablecap1=cat(table_nums(name="first_cars_table",caption='First car table'))
kable((cars[1:5,]))
tablecap2=cat(table_nums(name="second_cars_table",caption='second car table'))
kable(cars[6:10,])
tablecap3=cat(table_nums(name="third_cars_table",caption='third car table'))
kable(cars[10:15,])
```
The results:
A (terrible) workaround is to manually give the number ordering using display = FALSE. For example, inserting the following at the start of the document will ensure t1-t5 are sequentially numbered, no matter where the tables or first citations appear:
`r table_nums('t1', display = FALSE)`
`r table_nums('t2', display = FALSE)`
`r table_nums('t3', display = FALSE)`
`r table_nums('t4', display = FALSE)`
`r table_nums('t5', display = FALSE)`
I have not examined the captioner code but I expect that the document is read from top to bottom once and hence the numbering is stored in a first come, first served basis. Thus, I am not sure there are any other ways to get around this as it would involve some kind of pre-processing stage.
I would like to show, in an rmarkdown document, the printed output of a tibble as shown in the console. i.e.
First line: dimension summary;
then the column headers;
then classes of variables;
then first 10 lines of the tibble;
then number of rows not shown.
However, by default, tibbles and other data.frame objects are automatically converted to a tabbed, paginated table showing all contents.
I note that the option to turn off this default behaviour can be set for a whole markdown document by changing the df_print option to tibble in the YAML.
However, how do I set the df_print option to tibble for just a single R code chunk, so that I can show in an Rmarkdown document what the user will see on the console?
Thanks,
Jon
There's no need to touch the global setting. You can explicitly call the print function tibble:::print.tbl_df(df)
Example:
title: "Untitled"
author: "TC"
date: "7/27/2018"
output:
html_document:
df_print: "kable"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## print tibble
```{r}
df <- tibble::as.tibble(mtcars)
tibble:::print.tbl_df(head(df))
```
## print kable (set in YAML header)
```{r}
head(df)
```
output html
I want to write about the binomial distribution in a rmd document but I cannot work out how to represent the large bracket which surround two values written above one another. (Reads x choose y)
Any thoughts?
Tried various configurations of "choose" and "binom" but no joy.
Using RStudio, this is what my .Rmd file looks like:
---
title: "Untitled"
author: "sahir"
date: "March 12, 2015"
output: html_document
---
$$P(X \leq k) = \sum_{y \leq k} \binom{n}{y} p^y (1-p)^{n-y}$$