1

I'm using \newpage to force my figures to be in the right spot. I have added \newpage after the figure chunk. However, the figure caption is ignored when rendering the PDF.

I have tried fig.pos to force my figures, but it didn't work. I've also tried \clearpage and \pagebreak. None of them seem to work. Any idea what I'm doing wrong, or what I need to add to make it work?

Here's an example:

```{r eg, fig.width=4, fig.height=6, echo=FALSE, fig.pos="!H", fig.cap="\\label{fig:eg}Plot example", dev='png'}

 plot(c(1:20))

```

\newpage

some text some text 

some other figure (with proper caption)

some text

In the PDF version after using the figure label, I only see Figure?? as the caption.

blep
  • 726
  • 1
  • 11
  • 28
Noosh
  • 647
  • 1
  • 6
  • 11
  • I can't confirm the error; with your example I do obtain the caption in the PDF output. Please post a minimal working example which produces the undesired results. – RHertel Sep 18 '15 at 05:43
  • Thanks for checking. I cannot confirm it either with this example. I don't know what's wrong with my report. All figures have caption, except the two chucks that I'm using the \clearpage (or \newpage). My report is a bit complicated and it used multiple packages, that's why I couldn't put it here. I understand that I have to provide an example, but I was wondering if anybody has a similar problem. Could you please tell me how I can handle figure position, to force the figure be shown on the spot I want? – Noosh Sep 18 '15 at 16:36
  • Sorry, I don't know about precise instructions on how to handle the position of images. Just one comment concerning the missing caption: you might want to make sure that there's an empty line between the end of the chunk ```` and the \newpage command (like in in your example above). Else I think that the caption won't be displayed - I don't know why. Wishing you good luck! – RHertel Sep 18 '15 at 16:52

1 Answers1

0

I have the same issue and here is a reproducible result.

For me, the problem comes about when I use the lscape package to have one page landscape. using header.tex:

\usepackage{lscape}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}

Here is a code that produces undesired results.

---
title: "Figure missing for new landscape page"
author: "Tamara vdDoes"
date: "August 31, 2016"
output:
  pdf_document:
    fig_caption: yes  
    includes: 
      in_header: header.tex
---

# Figure title that works
```{r eg, fig.width=4, fig.height=6, echo=FALSE, fig.cap="Figure that works"}
plot(c(1:20))
```

\newpage
\blandscape

# Figure title that does not work
```{r eg2, fig.width=4, fig.height=6, echo=FALSE, fig.cap="Figure that does not work"}
plot(c(1:20))
```
\elandscape

`

Community
  • 1
  • 1
Tamara vdD
  • 113
  • 1
  • 6