25.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.1.0 by xtable 1.8-4 package % Sat Jun 5 10:50:18 2021

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 the text using the \@ref(MyTable) LaTeX command. Thus, in the source document we use `Table \@ref(MyTable)`'' to produceTable ??’’ in the documnet.

print(xtable(ds, 
             digits=0, 
             caption="Selected observations from **weatherAUS**.",
             label="MyTable"),
      include.rownames=FALSE)
% latex table generated in R 4.1.0 by xtable 1.8-4 package % Sat Jun 5 10:50:18 2021

The references to Table ?? can appear anywhere in the document. We can even refer to its page number by replacing \@ref(MyTable) with \pageref{MyTable} to get Table ?? on Page .

–>



Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.