I am using huxtable to display tables in RMarkdown for output: pdf_document.
When I put a label in the table
huxtable(mytable) %>%
set_label("tab:mylabel")
and then make a reference in the body text like
See Table \#ref(tab:mylabel) for more details
It displays "See Table #ref(tab:mylabel) for more details" rather than giving the table number.
This was covered for Bookdown in
Huxtable package for R: How to correctly reference huxtables in bookdown?
Do I need some special option or other setting to make it work for a regular PDF document?
Seems so. The rmarkdown guide says you will need "a bookdown format" to use cross-referencing in that way. However, there's an alternative: use embedded TeX, rather than this rmarkdown format. A MWE:
```{r}
hux("A huxtable") %>%
set_label("tab:foo") %>%
set_caption("You'll need a caption too")
```
Here's a reference to \ref{tab:foo}.
Related
Using quarto's HMTL-output functionalities, I am trying to produce a kable from a data.frame that contains some Markdown-style formatting that should show up in the final document. In the actual use case, I have a number of documents already formatted this way and I would like re-use these commands for correctly rendering the output.
Here's my example.qmd:
---
title: "example"
format:
html
---
```{r setup}
library(kableExtra)
```
```{r}
#| echo: false
data.frame(Function = "`read_delim()`",
Formula = "$\\leftarrow$",
Break = "this continues on a<br>new line",
Link = "[Google](www.google.com)") |>
kbl(format = "html")
```
After running the chunk, the preview in RStudio does display the arrow and line break correctly, but ` ` and the link fail to have an effect:
When rendering the qmd to HTML, the result looks like this, i.e. ignores the formatting:
What am I missing? Is there a way to include such formatting commands into a kable when rendering a quarto document to HTML?
When creating a table in Quarto, you can't mix Markdown with HTML - the Markdown syntax won't be processed within the HTML table.
This R code would work
data.frame(Function = "`read_delim()`",
Formula = "$\\leftarrow$",
Break = "this continues on a<br>new line",
Link = "[Google](www.google.com)") |>
kbl(format = "markdown")
So if you can, output only Markdown table which knitr::kable() should do by default.
If you need to output a HTML table (e.g for specific HTML features), you need to use a framework that will render the markdown for you while creating the HTML table.
gt with fmt_markdown() and md()
flextable with ftextra and colformat_md() or as_paragraph_md
This is possible that this limitation of note being able to include raw Markdown inside HTML table will be improve in the future (https://github.com/quarto-dev/quarto-cli/discussions/957#discussioncomment-2807907)
I am pretty sure that I've seen that it was possible to setup kable or some other Rstudio-supported table package as default when I rmarkdown:::render a Rmd document.
I cannot find if this is a yaml option or something that can be knitr::opts_chunk$set()
What I want is to stop having to do
```{r}
table = f()
table %>% head() %>% kable(table) # or something equivalent so the table is 'nicely' displayed
```
It depends on your output format (which you didn't mention). For example, for html_document, there is a df_print option, and you can set it to kable.
I tried to use pander tables in a markdown page that is generated from R-markdown files like Yihui describes in an example page.
In my _config.yml I have the markdown type set to markdown: kramdown. I know that some things are different in this markdown type compared to the markdown knitr uses per default. So if I compile my page in RStudio with knitr the table looks alright. If I compile the page with jekyll the table looks not formatted right.
```{r key}
library(pander)
LETTERSplus <- c(LETTERS, "_", ".", ",", "-")
key <- sample(LETTERSplus)
names(key) <- LETTERSplus
pander(key)
```
Compiled with knitr inside RStudio it looks alright:
Compiled with Jekyll it looks like this:
I don't want to use kable since it formats the table differently and there is now column wrap if the table is too long.
Do I have to set some special pandoc options to make this work? Options to define the markup type pandoc has to output? I don't see any other options inside the pander() function.
I was looking for a way to change the setting in my Rmd file so that the html output contains all the columns and the table does not break. I tried to change the css properties as in this solution (Output table width in Rmarkdown) but this does not affect my output.
I have currently 17 columns and using a pandoc.table, but only 5 coloumns are shown before the table is broken and the next 5 columns are displayed below.
What changes do I need to make so that the entire table can be shown in my html output?
Thanks for your help.
I can't use the pandoc package because is not currently available for R version 3.2.0. Instead, I used knitr with the kable() function. This code works fine:
{r, echo=FALSE, results='asis'}
library(knitr)
examp <- data.frame(matrix(rep("Unicorn"), nrow=5, ncol=100))
kable(examp)
I think, because you don't provide an example, that you need to specify the results='asis' chunk option.
Try ?kable for further information.
Anyway ?pandoc.table shows that there is an option split.table that may help.
I'm converting a markdown document to a PDF document using Pandoc from within R. I'm trying to centre the title.
So far, I've tried:
<center># This is my title</center>
and
-># This is my title<-
but neither have worked. Is there a way to centre the title when converting from markdown to PDF using Pandoc?
pandoc has its own extended version of markdown. This includes a title block.
If the file begins with a title block
% my title
% Me; Someone else
% May 2013
This will be parsed into LaTeX and the resulting pdf as
\title{my title}
\author{Me \and Someone Else}
\date{May 2013}
and then `
\maketitle
called within the document.
This will create the standard centred title.
If you want to change how the title etc is formatted you could use the titling package.
If you want to change how the section headers are formatted, you could use the titlesec package.
To automagically have pandoc implement these you could define your own template. A simpler option is to have a file with your desired latex preamble to be included in the header. and then use the appropriate arguments when calling pandoc (eg -H FILE or --include-in-header=FILE)