I want to change the numbering of the tables in the RMarkdown document so that all tables in the appendix have an "A-" in front of the number, thus: "Table A-2".
Only in the appendix. Otherwise with normal numbering ("Table 1").
However, I am not really getting anywhere.
Here is my reproducible example:\
---
title: "This is my title"
date: "`r Sys.setlocale(locale = 'English') ; format(Sys.time(), '%B %d, %Y')`"
output: pdf_document
---
```{r echo = F, message = F, warning = F}
library(tidyverse)
library(knitr)
``` #The hash mark must be removed!
# Results
```{r echo = F, message = F, warning = F}
tribble(~column1, ~column2,
"value1", 2,
"value2", 5
)%>%
kable(booktabs=T, caption = "This is the caption of the first table")
```
# Appendix
```{r echo = F, message = F, warning = F}
tribble(~column1, ~column2,
"value1", 6,
"value2", 8
)%>%
kable(booktabs=T, caption = "This is the caption of the second table")
```
This is really a LaTeX question, and I found the answer here.
You add these LaTeX lines after your Appendix title:
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
Related
I would like do add an icon to the text in one of the slides.
I've tried a few things but the end result is unstable. The icon are being printed in the html file, but If I add a slide or some text the the icons dissapear. Even if I revert what I've done with Ctrl+Z to previous working code the icons don't get printed...
I might be missing something, but the bookdown documentation didn't have anything on the subject...
---
title: 'Title'
author: "Author"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
ioslides_presentation:
self_contained: true
incremental: false
---
```{r knitr_init, echo=FALSE, message=FALSE, warning=FALSE, cache=FALSE}
## Global options
library(knitr)
library(shiny)
opts_chunk$set(
cache = FALSE,
prompt = FALSE,
tidy = FALSE,
comment = NA,
message = FALSE,
warning = FALSE
)
library(tidyverse)
library(plotly)
```
## S1
`r shiny::tags$i(class = "fa fa-arrow-down",style = "color: rgb(0,166,90)")`
item 3
`r shiny::tags$i(class = "fa fa-arrow-down",style = "color: rgb(0,166,90)")`
item 2
## S2
```{r, echo=F}
data.frame(a=1:10, b=1:10) %>%
plot_ly(x=~a,y=~b)
```
Writing the icons as <i class="fa fa-arrow-down" style="color: rgb(0,166,90)"></i> didn't seem to work either.
One option is to use the package icon (more information here).
---
title: 'Title'
author: "Author"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
ioslides_presentation:
self_contained: true
incremental: false
---
```{r knitr_init, echo=FALSE, message=FALSE, warning=FALSE, cache=FALSE}
## Global options
library(knitr)
library(shiny)
opts_chunk$set(
cache = FALSE,
prompt = FALSE,
tidy = FALSE,
comment = NA,
message = FALSE,
warning = FALSE,
echo=FALSE
)
library(tidyverse)
library(plotly)
library(icon)
```
## S1
```{r icon-style1}
icon_style(fontawesome("arrow-down", style = "solid"), scale = 2, fill = "#00A65A")
```
item 3
```{r icon-style2}
icon_style(fontawesome("arrow-down", style = "solid"), scale = 2, fill = "#00A65A")
```
item 2
## S2
```{r, echo=F}
data.frame(a=1:10, b=1:10) %>%
plot_ly(x=~a,y=~b)
```
-output
I just added two code chunks, one for each icon. Additionally, in your first r chunk, I added echo=FALSE to the opts_chunk$set and library(icon). In order to achieve the RGB color you chose, the HEX code was needed (#00A65A).
I'm trying to render a pander table in RMarkdown that includes superscript. Here is my current RMarkdown code:
```
---
title: "My Table"
output: html_document
---
```{r packages, include = FALSE}
library(tidyverse)
library(pander)
```
```{r my_table}
my_table <-
data.frame(
c("Sector 1",
"Sector 2",
"Sector 3"),
c("100%",
"29%",
"NA"))
pander(my_table,
col.names = c("Sector", "% Coverage"),
split.cells = 40,
keep.line.breaks = TRUE)
```
And here is the knit result:
I would like to add a superscripted letter "c" to the "NA" cell of the table, yielding an output like this:
You are looking to use the notation $$ NA^c $$, but this only works outside of the R chunk at the moment.
I am attempting to generate a PDF from a Bookdown script which includes a complex table. The table includes some parameter names that have subscripts in them. I would also like to colour some of the rows. An example script is shown below:
---
title: "Example problem"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: book
output:
#bookdown::gitbook: default
bookdown::pdf_book: default
always_allow_html: yes
---
This is a test example for the problem.
```{r}
library(magrittr)
library(knitr)
library(kableExtra)
df <- data.frame(Parameter = c("NO~x~ emissions", "SO~2~ emissions", "CO~2~ emissions"), "Value mg/Nm^3^" = c(800,900,1000),check.names=F)
knitr::kable(df,escape = F, caption = 'Example table!', booktabs = TRUE, format = "latex") %>% #
row_spec(0, bold = T, color = "white", background = "#045a8d") %>%
row_spec(c(2), bold = T, color = "white", background = "#3690c0")
```
blah blah
I can run the script using the kable format as 'format = "html"' and the result looks fine including the coloured rows and subscripts. When I change the format to Latex, the subscripts are not displayed properly in the produced pdf.
I have tried adding the argument escape = F to kable, but the build process fails.
Quitting from lines 14-23 (_main.Rmd)
Error in kable_latex(x = c("$NO_{x}$ emissions", "SO2 emissions", "CO2 emissions", :
unused argument (example = FALSE)
Calls: <Anonymous> ... eval -> %>% -> eval -> eval -> <Anonymous> -> do.call
Can anyone help solve this problem?
For me it works if I use (escaped) LaTeX syntax:
---
title: "Example problem"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: book
output:
bookdown::pdf_book: default
#bookdown::gitbook: default
always_allow_html: yes
---
This is a test example for the problem.
```{r}
library(magrittr)
library(knitr)
library(kableExtra)
df <- data.frame(Parameter = c("NO\\textsubscript{x} emissions", "SO\\textsubscript{2} emissions", "CO\\textsubscript{2} emissions"),
"Value mg/Nm\\textsuperscript{3}" = c(800,900,1000),
check.names = F)
knitr::kable(df,escape = F, caption = 'Example table!', booktabs = TRUE, format = "latex") %>% #
row_spec(0, bold = T, color = "white", background = "#045a8d") %>%
row_spec(c(2), bold = T, color = "white", background = "#3690c0")
```
blah blah
The section of the bookdown manual on generating figures demonstrates a case where include_graphics() can be given a vector of paths of length > 1, producing a number of subplots with a single caption:
However, when I try this in my fork of thesisdown, in the PDF output I get the figure caption (and, judging by the spacing, the entire figure environment) repeated for each subplot. Here is a reproducible example:
---
output: bookdown::pdf_document2
toc: false
---
```{r, echo = FALSE}
for(i in 1:3){
jpeg(filename = paste0("temp_", i, ".jpg"), width = 600, height = 250)
plot(cars)
title(main = i)
dev.off()
}
```
```{r fig.cap = "Caption", out.width="100%", fig.ncol = 1, echo = FALSE}
knitr::include_graphics(paste0("temp_", 1:3, ".jpg"))
```
I was hoping more for the five images stacked, with a single caption at the bottom. This also appears to be breaking the figure cross-referencing, as each plot has its own figure number and cross-references to the chunk render as ??.
Getting subfigures requires a few additional settings to be set in the chunk header.
fig.subcap is a list of the captions for subfigures
fig.ncol: the number of columns of subfigures
out.width: the output width of the figures. You will normally set this 100% divided by the number of sub columns.
Subfigures are built using the subfig package. You can either include this within your LaTeX bookdown template, or alternative you can added it to the YAML as follows:
Here is an example:
---
output: bookdown::pdf_document2
toc: false
header-includes:
- \usepackage{subfig}
---
```{r, echo = FALSE}
for(i in 1:3){
jpeg(filename = paste0("temp_", i, ".jpg"), width = 600, height = 250)
plot(cars)
title(main = i)
dev.off()
}
```
```{r fig.cap = "Caption", out.width="100%", fig.ncol = 1, echo = FALSE, fig.subcap= c("First", "Second", "Third")}
knitr::include_graphics(paste0("temp_", 1:3, ".jpg"))
```
I am trying to to use xtable() and the longtable environment to display a multi=page table.
Currently when you run the code it will show "\scalebox " at the top and then it will cutoff columns of the table.
How do you remove the "\scalebox" at the top and show all the column in a readable manner?
Thank you.
here is the code:
---
title: "test"
output: pdf_document
keep_tex: TRUE
setspace: singlespacing
geometry: margin=1.1cm
header-includes:
- \usepackage{color}
- \usepackage{amsmath}
- \usepackage{xcolor}
- \usepackage{colortbl}
- \usepackage{tabulary}
- \usepackage{tabularx}
- \usepackage{longtable}
- \usepackage{ltxtable}
fig.lp: ('';character)
fig.pos: "H"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE , comment = NA, message= FALSE, warning = FALSE)
```
```{r one, include= FALSE}
n=600
table = data.frame(name = rep(" dakjf aslkj dklsfj aslj ldjs",n),
NUMERICFIELDNUMBERa = rep(10000,n),
NUMERICFIELDNUMBERb = rep(10000,n),
NUMERICFIELDNUMBERc = rep(10000,n),
NUMERICFIELDNUMBERd = rep("1250 + 52.33",n),
NUMERICFIELDNUMBERe = rep("25.6 + 36.25",n),
NUMERICFIELDNUMBERf = rep(10000,n),
NUMERICFIELDNUMBERg = rep(10000,n)
)
head(table)
colnames(table) = c("GROUP NAME",
"Numeric Field Number1",
"Numeric Field Number2",
"Numeric Field Number3",
"Numeric Field Number4",
"Numeric Field Number5",
"Numeric Field Number6",
"Numeric Field Number7"
)
rownames(table) = NULL
```
```{r echo= FALSE, comment = FALSE, message= FALSE, warning = FALSE, results='asis'}
library(xtable)
options(xtable.include.rownames=F)
options(xtable.scalebox=.7)
#options(xtable.tabular.environment = "tabulary")
#options(xtable.width = "7in")
options(xtable.comment=F)
options(xtable.floating = F)
t = xtable(table)
#align(t)= "cccccccc"#"cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}" #rep("p{2cm}C",8)#"p{1cm}cccccccc"
#align(t) = "cp{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}"
print(t, sanitize.text.function = identity)
```