0

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

Portrait Orientation

Landscape Orientation

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')
```
  • 1
    you would need to reset some more lengths but it is best not to use such low level setting, either use the rotating package and use sidewaysfigure instead of figure or use lscape package and use \begin{landscape}.\begin{figure}...\end[landscape} – David Carlisle Jun 22 '18 at 17:32
  • Also note pdflscape, which cause landscape pages to appear upright. – John Kormylo Jun 22 '18 at 23:00
  • Thanks for your comments. I used this setting as it was described in a post here. If I use the suggestions you recommend. I lose the rotations of my headers [img]i.imgur.com/Mo3vyKH.png[/img] – Patrick Jun 24 '18 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.