figRef: Figure and Table cross-references

Description Usage Arguments Details Value Author(s) Examples

Description

Define figure and table labels and reference them in the text to create automatic reference the corresponding table or figure. Numbers are assigned automatically.

Usage

1
2
3
4
5
6
7
8
9
figRef(label, caption, target, prefix = knitr::opts_knit$get("figcap.prefix"),
  sep = knitr::opts_knit$get("figcap.sep"),
  prefix.highlight = knitr::opts_knit$get("figcap.prefix.highlight"),
  markup = TRUE)

tabRef(label, caption, target, prefix = knitr::opts_knit$get("tabcap.prefix"),
  sep = knitr::opts_knit$get("tabcap.sep"),
  prefix.highlight = knitr::opts_knit$get("tabcap.prefix.highlight"),
  markup = TRUE)

Arguments

label

Identifying label.

caption

Caption to display.

target

An object of class Dependency.

prefix

Fixed part of the printed label. Defaults to 'Figure' for figures and to 'Table' for tables.

sep

Separator to use between printed label and caption.

prefix.highlight

Markdown code the figure label should be wrapped in. Allows the label to be displayed in bold or italics.

markup

Logical indicating whether the label that is returned when caption is missing should be marked up as a link.

Details

Typically figRef only needs to be called explicitly to refer to figures in the text. The call to set the label and generate the appropriately modified caption is issued automatically when a code chunk with the fig.cap option is encountered. In that case the label used in the reference should be the label of the code chunk that generated the figure. Note that this means code chunks that generate figures have to be named.

Reference can occur at any point in the text. It is not strictly necessary to define a label before it is referenced. However, numbering is determined by the order in which labels are first encountered and this can lead to figures or tables appearing to be out of order.

It is possible to refer to figures in other documents by supplying a Dependency object to argument target. This will generate a reference of the form "Short Title, Figure Label", e.g. "Methods, Figure 1". It is an error to provide a target as well as a caption.

Value

If the caption argument is present a string combining the (computed) figure label with the caption. Otherwise a (markdown formatted) link to the figure is returned.

Author(s)

Peter Humburg

Examples

1
2
3
4
5
knitr::opts_knit$set('figcap.prefix','Figure')
knitr::opts_knit$set('figcap.prefix.highlight', '**')

figRef('foo', 'A test caption')
figRef('foo')

humburg/reportmd documentation built on May 17, 2019, 9:13 p.m.