28.14 Formatting Tables Using XTable
REVIEW Whilst knitr::kable() provides basic functionality much more extensive control over the formatting of tables is provided by (Dahl et al. 2019). By default the table produced is called a floating table so that it floats within the document to an appropriate location.
As a floating table we will add a caption= and a table reference label= to the table so that they do not get lost. We can then refer to the table within the text and have the tables appear somewhere convenient automatically. The code block below, for example, produces TableĀ ??. The table and page numbers are automatically assigned to the table. Within LaTeX we can access the table number
# Load the package from the local library into the R session.
library(xtable)
# Generate a floating table with a caption.
ds %>% xtable(caption="Example xtable.", label="egtbl")Also note that by default missing values (NA) are not printed
nor are the extra lines that are printed by default when using
knitr::kable().
There are very many formatting options available for fine tuning how the table is to be presented and we cover some of these in the following pages. We also note that some options are provisioned by xtable::xtable() whilst others are available through xtable::print.xtable(). An example option is include.rownames= which is an option available with xtable::print.xtable(). The result is seen in TableĀ ??.
% latex table generated in R 4.6.1 by xtable 1.8-4 package % Tue Sep 1 17:12:43 2026References
If you find this curated material useful then you can consider a donation to support it's ongoing availability and give you access to the PDF version of this book. The material has been scoped up by Generative AI without permission or any kind of recompense so do consider a donation if you can afford it. Unlike Generative AI your access to this materials is freely given. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Togaware has a 30 year tradition of making popular open source software which includes sold privacy preserving productivity apps, rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0