Add a title into a "docx"
object.
# S3 method for docx
addTitle (doc, value, level, ...)
Object of class "docx"
"character"
value to use as title
text
"integer"
positive value to use as
heading level. 1 for title1, 2 for title2, etc.
further arguments, not used.
an object of class "docx"
.
In MS Word, you can use whatever style you want as title formating 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.
docx
, addParagraph.docx
,
declareTitlesStyles.docx
,
styles.docx
# 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 DataLab