ReporteRs (version 0.7.1)

addTitle.docx: Insert a title into a docx object

Description

Add a title into a docx object.

Usage

# S3 method for docx
addTitle(doc, value, level = 1, ...)

Arguments

doc

Object of class docx

value

"character" value to use as title text

level

"integer" positive value to use as heading level. 1 for title1, 2 for title2, etc. Default to 1.

...

further arguments, not used.

Value

an object of class docx.

Details

In MS Word, you can use whatever style you want as title formatting style. But to be considered as entries for a Table of Content, used styles must be 'title' styles. Theses are always available in MS Word list styles. When template is read, ReporteRs try to guess what are theses styles. If it does not succeed, you will see that error when addTitle will be called:

Error in addHeader(... You must defined title styles via declareTitlesStyles first.

You have to use function declareTitlesStyles.docx to indicate which available styles are meant to be used as titles styles. A side effect is that you will be able then to add a table of content in your Word document.

See Also

docx, addParagraph.docx , declareTitlesStyles.docx, styles.docx

Examples

Run this code
# NOT RUN {
#START_TAG_TEST
# Create a new document
doc = docx( title = "title" )

# add a title (level 1)
doc = addTitle( doc, "My first title", level = 1 )

# add another title (level 2)
doc = addTitle( doc, "My first sub-title", level = 2 )
doc = addParagraph(doc, "Hello Word!", stylename = "Normal")

# Write the object in file "addTitle_example.docx"
writeDoc( doc, "addTitle_example.docx" )
#STOP_TAG_TEST
# }

Run the code above in your browser using DataCamp Workspace