Description Usage Arguments Details Value See Also Examples
Add a table of contents into a document object
1 2 3 4 |
doc |
document object |
... |
further arguments passed to other methods |
stylename |
optional. Stylename in the document that will be used to build entries of the TOC. |
level_max |
max title level to show in the TOC (defaut to 3, from title1 to title3). |
When working with docx
object:
If stylename is not used, a classical table of content will be produced.
If stylename is used, a custom table of contents will be produced,
pointing to entries that have been formated with stylename
.
For example, this can be used to produce a toc with only plots.
a document object
docx
, styles
,
addTitle
, addParagraph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # simple TOC -----
# Create a new document
doc = docx( title = "title" )
#leave the first page blank and add a page break
doc = addPageBreak(doc)
# add a TOC (to be refresh when document is opened)
# and add a page break
doc = addTOC(doc)
doc = addPageBreak(doc)
# add titles that will be entries in the TOC
doc = addTitle( doc, "My first title", level = 1 )
doc = addTitle( doc, "My second title", level = 1 )
# Write the object in file "addTOC_example1.docx"
writeDoc( doc, "addTOC_example1.docx" )
# custom TOC -----
doc = docx( title = "title" )
#leave the first page blank and add a page break
doc = addPageBreak(doc)
doc = addTitle( doc, "Plots", level = 1 )
doc = addPlot( doc, fun = plot,
x = rnorm( 100 ),y = rnorm (100 ),
main = "base plot main title"
)
doc = addParagraph( doc, value="graph example 1", stylename = "rPlotLegend" )
if( requireNamespace("ggplot2", quietly = TRUE) ){
myplot = ggplot2::qplot(Sepal.Length, Petal.Length,
data = iris, color = Species,
size = Petal.Width, alpha = I(0.7))
doc = addPlot( doc = doc, fun = print,
x = myplot #this argument MUST be named, print is expecting argument 'x'
)
doc = addParagraph( doc, value="graph example 2",
stylename = "rPlotLegend" )
}
# Because we used "rPlotLegend" as legend in plot
# , addTOC will use this stylename to define
# entries in the generated TOC
doc = addTOC(doc, stylename = "rPlotLegend")
# Write the object in file "addTOC_example2.docx"
writeDoc( doc, "addTOC_example2.docx" )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.