Skip to content

Commit

Permalink
fix rstudio/rmarkdown#2518: when fig.num is a multiple of fig.ncol, a…
Browse files Browse the repository at this point in the history
…dd \newline to the last subfigure
  • Loading branch information
yihui committed Oct 11, 2023
1 parent de0e471 commit 607148d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.44.2
Version: 1.44.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Negative numbers returned from inline R expressions lost their minus signs when formatted in the scientific notation (thanks, @fkohrt, #2288).

- Add the necessary `\newline` to the last subfigure (thanks, @slrellison, rstudio/rmarkdown#2518).

## MAJOR CHANGES

- `opts_current$set()` without `opts_current$lock(FALSE)` will trigger a warning instead of an error for now and it will become an error in future (#2296).
Expand Down
5 changes: 4 additions & 1 deletion R/hooks-latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ hook_plot_tex = function(x, options) {
fig.ncol = options$fig.ncol %n% fig.num
if (is.null(fig.sep <- options$fig.sep)) {
fig.sep = character(fig.num)
if (fig.ncol < fig.num) fig.sep[seq(fig.ncol, fig.num - 1L, fig.ncol)] = '\\newline'
# add \newline after every fig.ncol figures; if the last figure is not the
# last on its row, skip adding \newline (not necessary, but may be harmless)
if (fig.ncol < fig.num)
fig.sep[seq(fig.ncol, fig.num - (fig.num %% fig.ncol > 0), fig.ncol)] = '\\newline'
}
sep.cur = NULL

Expand Down

0 comments on commit 607148d

Please sign in to comment.