Skip to content

Figure Captions with Multiple Figures and echo=FALSE Does not Print the Caption #1524

@billdenney

Description

@billdenney

When printing multiple figures per chunk (and maybe in other scenarios with multiple outputs per chunk), figure captions do not show up unless extra line breaks are inserted between them. In the example below, the first and third chunks caption as expected, but the second does not. (This is similar to #820, but it still appears to be an issue.)

---
title: "Test2"
author: "William Denney"
date: "March 14, 2018"
output:
  pdf_document:
    keep_tex: yes
    fig_caption: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
cap_vec <- c("howdy", "foo")
```


# With echo=TRUE

When `echo = TRUE`, the captions print as expected.

```{r fig.cap=cap_vec, echo=TRUE}
plot(pressure)
plot(temperature~1/pressure, data=pressure)
```

\clearpage

# With echo=FALSE

When `echo = FALSE`, the captions do not print.

```{r fig.cap=cap_vec, echo=FALSE}
plot(pressure)
plot(temperature~1/pressure, data=pressure)
```

\clearpage

# With echo=FALSE and new lines

When `echo= FALSE` and new lines are added between figures via cat, it works.

```{r fig.cap=cap_vec, echo=FALSE}
cat("\n\n")
plot(pressure)
cat("\n\n")
plot(temperature~1/pressure, data=pressure)
cat("\n\n")
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature requests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions