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.4.1 by xtable 1.8-4 package
% Sat Dec 14 08:48:59 2024
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 produce
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.4.1 by xtable 1.8-4 package
% Sat Dec 14 08:48:59 2024
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 .
–>