8

I notice that you can center and middle the layout of a slide using class: center, middle in xaringan slides, but that changes the title and layout of the entire slide. You can also center the image by:

.center[
![]('foo.svg')
]

But I wonder if I can center the plot and also make it at middle of the slide without changing the layout of the entire page in xaringan?

Thanks!

Miao Cai
  • 902
  • 9
  • 25
  • I quickly checked `.center.middle[]` but it's not working. but I think it's not hard to tackle. This question indicates that our wiki needs to improve! https://github.com/yihui/xaringan – TC Zhang Nov 28 '18 at 06:54
  • Yeah `middle` works only for remark slide as a whole. I have a work around creating a class `vmiddle` for this which I'll post soon. – Emi Dec 02 '18 at 19:01
  • Oops I realised my work around only works on my theme because of the way I define the columns. I guess the easiest way to adjust is to include lots of `
    ` for now
    – Emi Dec 02 '18 at 19:08
  • @Emi Thanks for your response. Could you post an answer with replicable codes? – Miao Cai Dec 02 '18 at 22:33

1 Answers1

13

Try this: define a .center2 class at the beginning of your rmd or in a separate CSS file:

<style>

.center2 {
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

</style>

Then insert the image, wrap it with .center2[] :

.center2[
```{r echo = FALSE}
knitr::include_graphics("path/to/image")
```
]
TC Zhang
  • 2,757
  • 1
  • 13
  • 19
  • Thank you for your response. From my understanding, .fig.align = 'center' can horizontally center the figure in Rmarkdown, but can I center the figure both vertically and horizontally, .i.e. put the figure at the very middle of the slide. I think this is usefully when we need to put the figure in the slide. – Miao Cai Dec 06 '18 at 16:57
  • Ahh, I see. so we have to deal with CSS styles here. I edited my answer, please have a try. – TC Zhang Dec 07 '18 at 00:02