Chapter 2 Cross referencing

2.1 Chapters or sections

Always give you sections an additional reference…e.g. # Cross referencing {#crossref} This gives us two reference points. The first we can use to reference the section name…

  1. We want to say see the Introduction (or other section label)we use …[Cross referencing] giving Cross referencing

But what if we want to reference the section number (e.g. Chapter 1 or section 4.2)

  1. Just reference the label we gave to the section….see Chapter \@ref(crossref) giving see Chapter 2

2.2 Figures, tables, even code chunks

2.2.1 Figures

When you create a figure, table or code chunk there is an option to name the chunk something. Do it!. Don’t be like me and not! Be warned that these chunk names can’t have any fancy or strange characters in them e.g. _. I think a - is allowed, but i’d keep it simple. Here is a figure. In the chunk options after r i have specified nice-fig, echo=FALSE, fig.cap='Here is a nice figure!', out.width='80%'

Here is a nice figure!

Figure 2.1: Here is a nice figure!

To cross reference this just include Figure \@ref(fig:nice-fig) which gives…Figure 2.1.

2.2.2 Tables

For tables i’d recommend using the kable package. Here is an example table, same deal as the Figures section with naming the code chunk.

knitr::kable(
  head(iris, 20), caption = 'Here is a nice table!',
  booktabs = TRUE
)
Table 2.1: Here is a nice table!
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa
5.4 3.7 1.5 0.2 setosa
4.8 3.4 1.6 0.2 setosa
4.8 3.0 1.4 0.1 setosa
4.3 3.0 1.1 0.1 setosa
5.8 4.0 1.2 0.2 setosa
5.7 4.4 1.5 0.4 setosa
5.4 3.9 1.3 0.4 setosa
5.1 3.5 1.4 0.3 setosa
5.7 3.8 1.7 0.3 setosa
5.1 3.8 1.5 0.3 setosa

Now to cite the table it’s just Table \@ref(tab:nice-tab), giving Table 2.1

2.3 Citing documents

To cite documents they need to be in a .bib file, that must be loaded within your index.Rmd with the bibliography: argument. Have a look at my index.Rmd and you will see there are three such files, two that were provided as an example here book.bib, packages.bib and one that i added test.bib. I can simply cite the papers within them using the citation key e.g. [@xie2015] giving (Xie 2015). Make sure you remove the ones you don’t need.

If you remove the citation from the [] it will give Xie (2015).

When citing multiple authors use a ; [@xie2015; @maclachlan2017urban] = (Xie 2015; MacLachlan et al. 2017)

To remove the author add a minus sign -@maclachlan2017urban = (2017)

2.4 Citing using software

Zotero can now continuously update your .bib file.

To do so:

  1. Download the latest release — the .xpi file: https://github.com/retorquere/zotero-better-bibtex/releases/tag/v5.2.108

  2. In Zotero > Tools > Add ons > Extensions

  3. Select the cog > Install add on from file

  4. Select the .xip > restart Zotero.

On the restart select the default naming convention.

To export the library

  1. File > export

  2. Select Better BibLaTex

  3. Click keep updated

  4. Select the file to save into your Thesis project

  5. Make sure you have the file listed in your bibliography in the index.Rmd file

You can also manage references using citr which makes finding them to cite much easier. In RStudio go: Addins (top tool bar) > insert citations.

2.5 Footnotes

To add a footnote use ^[This is a footnote] to create.1

References

MacLachlan, Andrew, Eloise Biggs, Gareth Roberts, and Bryan Boruff. 2017. “Urban Growth Dynamics in Perth, Western Australia: Using Applied Remote Sensing for Sustainable Future Planning.” Land 6 (1): 9.
Xie, Yihui. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. http://yihui.name/knitr/.

  1. This is a footnote↩︎