1

I have a R file running a Rmd file to generate a pdf (rmarkdown::render). I use fancyhdr to tune the layout, header,... As it is dynamic, I also use parameters (params). My question is, which command should I use to split the title in two lines ? I refer to that post, but none of the proposed solutions work. And I don't know if it is a question for R people or for those of Latex/Lualatex...

Here is my code in R, you may use your own path and fname (figure name) if you want to reproduce the code.

          rmarkdown::render("your path/Fig_generator.Rmd", 
                            output_file = file.path(your path, paste("test",".pdf", sep = "")),
                            encoding = "native.enc", 
                            params = list(
                              dyntitle = "This is a very very very very long line that I would like | to split where the | is",
                              dynsubtitle = "Some subtitle text",
                              dynfigno = "Fig. xx-x",
                              dynprojectname ="xxx / xxx",
                              dynimage = paste("your path/",fname,".","pdf",sep = "")))

Here is the code in Rmd:

---
#knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, ) })
template: default-1.17.0.2.tex
output: 
  pdf_document:
    latex_engine: lualatex
    keep_tex: true
documentclass: article
mainfont: Arial
fontsize: 12pt
params:
  dyntitle:  !r dyntitle
  dynsubtitle:  !r dynsubtitle
  dynfigno:  !r dynfigno
  dynprojectname:  !r dynprojectname
  dynimage:  !r dynimage
title: "`r params$dyntitle`"
subtitle: "`r params$dynsubtitle`"
figureno: "`r params$dynfigno`"
projectname: "`r params$dynprojectname`"
image: "`r params$dynimage`"
---

\includegraphics[width=7.27in]{`r params$dynimage`}

Can someone help me with that, please ?

Waylan
  • 37,164
  • 12
  • 83
  • 109
Julien
  • 139
  • 13
  • If you want to dynamically wrap your title (instead of having to provide the break points), check out [this answer](https://stackoverflow.com/a/27734975/3498910). This can be used like this: `title: "r wrap_sentences(params$dyntitle)"` – asachet Aug 21 '19 at 09:51
  • Can't you simply put a new line character `\n` wherever you want a line break? – asachet Aug 21 '19 at 09:57
  • I tried \n, \r, \n, \\\\, |, ... but no way. – Julien Aug 21 '19 at 10:09

1 Answers1

0

https://stackoverflow.com/a/28895263/11497260

If you combine that solution with your inline code - `r params$dyntitle` - it should work I guess.

Jannes
  • 23
  • 3