I want to center an image and/or text using R Markdown and knit a PDF report out of it.
I have tried using:
->Text<-
->![](image1.jpg)<-
There is now a much better solution, a lot more elegant, based on fenced div
, which have been implemented in pandoc
, as explained here:
::: {.center data-latex=""}
Some text here...
:::
All you need to do is to change your css
file accordingly. The following chunk for instance does the job:
```{cat, engine.opts = list(file = "style.css")}
.center {
text-align: center;
}
```
(Obviously, you can also directly type the content of the chunk into your .css
file...).
The tex
file includes the proper centering commands.
The crucial advantage of this method is that it allows writing markdown
code inside the block.
In my previous answer, r ctrFmt("Centered **text** in html and pdf!")
does not bold for the word "text", but it would if inside a fenced div
.
For images, etc... the lua
filter is available here