and table number), I have written the function f.ref. In order to return the desired output (prefix Tab. 1: German Bundesliga: Final Table 2015/16, Position 7-12” Otherwise, we wi’ll get the following output: “Tab. However, we can not just use the inline code table_nums('tab_1') Since we have received a numbered table, it should also be possible to reference the table. 1: German Bundesliga: Final Table 2015/16, Position 7-12 Position It is important to separate inline code and code chunk. With fig.cap = tab.1_cap, we specify the caption of the first table. The next code snippet combines both inline code and a code chunk.
#Table rmarkdown pdf
table_nums <- captioner::captioner(prefix = "Tab.")Ĭaption = "German Bundesliga: Final Table 2015/16, Position 7-12")Ĭaption = "German Bundesliga: Final Table 2015/16, Position 12-18") How can I manually and simply format a table in RMarkdown that will look good when converted to HTML (using the knitr and markdown packages), PDF (using pandoc and miktex) and docx (using pandoc) I want to be able to write small tables in RMarkdown that are not a result of R functions that look good in the three formats I use most often. Furthermore, we may also define a prefix ( Tab. In a first step, we define a function named table_nums and apply it to the tables’ name and caption. Thanks to Alathea Letaw’s captioner package, we can number tables and figures. German Bundesliga: Final Table 2015/16, Position 1-6 Position As we can see, the caption will not be numbered and, thus, cannot be referenced in the document. With caption we can specify a simple table caption. In the first code snippet, we create a table using the kable function of the knitr package. For more information on how Github generates tables refer to Github's Markdown Documentation. Markdown native syntax, such as bold or inline code blocks, is easy to add to tables, and HTML tags can be used as well. Pacman::p_load(knitr, captioner, bundesligR, stringr) Github's flavor of markdown allows you to create some complex tables, but in many cases, it's best to keep it simple and easy to read. if (!require("pacman")) install.packages("pacman")
It contains “all final tables of Germany’s highest football league, the Bundesliga” ( Link). The dataset I will be using in this blog post is named bundesligR and part of the bundesligR package.
#Table rmarkdown install
The following code will install load and / or install the R packages required for this blog post.
#Table rmarkdown how to
In this blog post, I will explain how to number and reference tables and figures in R Markdown files using the captioner package. However, since bookdown uses LaTex functionality, R Markdown files created with bookdown cannot be converted into MS Word (.docx) files. The recently published bookdown package makes it very easy to number and reference tables and figures ( Link). Unfortunately, R Markdown has no “native” method to number and reference table and figure captions. However, in scientific research papers or reports, tables and figures usually need to be numbered and referenced.
R Markdown is a great tool to make research results reproducible.