Bug in R-Markdown or LaTeX problem?!

If you remove the word «Something!» from the following script, once knitting to pdf, the second plot instead of in the new page, is (partially) shown below the same page. If the plots are more than two, only the second has this issue, the other plots are shown normally in the following pages.

title: "Possible bug"
output: pdf_document

knitr::opts_chunk$set(echo = FALSE)

Here is the title. If I remove the word «Something!» from below, once knitting the pdf the second plot will not be shown correctly


par(mfcol=c(6,3), cex=0.6, mgp = c(0.8,0.6,0.1)
  , mai=c(0,0,0,0), omi=c(0.2,0.4,0.3,0.1))

a <- c(1:88)
b <- c(88:1)
d <- cbind(a, b)

# Plot data
for (j in (1:2)){
  for (i in (1:18)){

This is expected behavior because of LaTeX, where control of figure placement is very fussy. Something! does not leave sufficient space on the page to complete the figure. You can "fix" this by adjusting the page margins, fonts, etc. to leave extra space, but there can be no assurance that the adjustments will work for all figures on all pages.

Hi technocrat.
Writing "Something!" solves the problem, removing it creates the problem (and created me a lot of headaches).

Anyway, if it is a problem of LaTeX and not of its implementation in Markdown I suppose there is nothing I can ask for here.

This is probably due to floating in LaTeX. You can deactivate it if needed, but it could have other side effect

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.