I'm a newcomer to Latex but I've already found it very useful. I have a document that requires me to switch the orientation from portrait to landscape midway through the document so I can properly fit an image. I searched quite a few posts and was able to achieve it by doing the following in RMarkdown
\newpage
\paperwidth=\pdfpageheight
\paperheight=\pdfpagewidth
\pdfpageheight=\paperheight
\pdfpagewidth=\paperwidth
\headwidth=\textheight
\begingroup
\vsize=\textwidth
\hsize=\textheight
Once I flipped the orientation I could insert my code for the figure
```{r, fig.pos = "H",fig.align='center', fig.cap="P3b Amplitude Fz (E15)", echo=FALSE, out.height='550px', out.width='600px', dpi=300}
knitr::include_graphics("images/P3bAmp_E15.png")
```
And then flip the page orientation back to portrait.
\endgroup
\newpage
\paperwidth=\pdfpageheight
\paperheight=\pdfpagewidth
\pdfpageheight=\paperheight
\pdfpagewidth=\paperwidth
\headwidth=\textwidth
I have 2 issues that I am currently running into. The first is that the caption will not center according to the width of a landscape page. Below are screenshots


Does anyone have any input on how this may be fixed?
Here is the header I have for the document in case it might be of use
---
title: "Data Report"
author: "My Name Here"
output:
pdf_document:
keep_tex: yes
toc: true
toc_depth: 3
header-includes:
- \usepackage{pdflscape}
- \usepackage{graphicx}
- \usepackage{lipsum}
- \usepackage{fancyhdr}
- \usepackage{float}
- \pagestyle{fancy}
- \fancyhf{}
- \fancyhead[C]{Header}
- \fancyfoot[RO,RE]{\thepage}
---
```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.pos = 'H')
```
rotatingpackage and usesidewaysfigureinstead offigureor uselscapepackage and use\begin{landscape}.\begin{figure}...\end[landscape}– David Carlisle Jun 22 '18 at 17:32If I use the suggestions you recommend. I lose the rotations of my headers [img]https://i.imgur.com/Mo3vyKH.png[/img]
– Patrick Jun 24 '18 at 21:09