28.16 Adding a Caption and Reference Label

REVIEW We have seen captions and labels above but tell the story here in a slightly different way.

print(xtable(ds,
             digits=0,
             caption="Selected observations from **weatherAUS**."),
      include.rownames=FALSE)
% latex table generated in R 4.6.1 by xtable 1.8-4 package % Tue Sep 1 17:12:43 2026

Notice that we wanted to emphasise the name of the dataset in the caption. We can make it bold using the \textbf{} command of LaTeX within the string passed to caption=. We need to repeat the backslash because R itself will attempt to interpret it otherwise. That is, we escape the backslash.

As well as adding a caption with a table number, we can add a label to the xtable::xtable() command and then refer to the table within ``Table ??’’ in the documnet.

print(xtable(ds,
             digits=0,
             caption="Selected observations from **weatherAUS**.",
             label="MyTable"),
      include.rownames=FALSE)
% latex table generated in R 4.6.1 by xtable 1.8-4 package % Tue Sep 1 17:12:43 2026

The references to Table ?? can appear anywhere in the document. We can even refer to its page number by replacing Table ?? on Page .

–>



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