@@ -277,7 +277,8 @@ marquee_grob <- function(
277
277
collapsed_margins ,
278
278
has_background ,
279
279
has_top ,
280
- has_bottom
280
+ has_bottom ,
281
+ if (force_body_margin ) 0 else NULL
281
282
)
282
283
}
283
284
# Body margin wins over any collapsing
@@ -1373,15 +1374,17 @@ get_last <- function(tree, background, border) {
1373
1374
tree $ element
1374
1375
}
1375
1376
}
1376
- set_margins <- function (tree , margins , has_background , has_top , has_bottom ) {
1377
+ set_margins <- function (tree , margins , has_background , has_top , has_bottom , forced_margin = NULL ) {
1377
1378
tops <- get_first(tree , has_background , has_top )
1378
- margins $ top [tops [1 ]] <- max(margins $ top [tops ])
1379
+ margins $ top [tops [1 ]] <- forced_margin % || % max(margins $ top [tops ])
1379
1380
margins $ top [tops [- 1 ]] <- 0
1380
1381
bottoms <- get_last(tree , has_background , has_top )
1381
- margins $ bottom [bottoms [1 ]] <- max(margins $ bottom [bottoms ])
1382
+ margins $ bottom [bottoms [1 ]] <- forced_margin % || % max(margins $ bottom [bottoms ])
1382
1383
margins $ bottom [bottoms [- 1 ]] <- 0
1383
- for (child in tree $ children ) {
1384
- margins <- set_margins(child , margins , has_background , has_top , has_bottom )
1384
+ for (i in seq_along(tree $ children )) {
1385
+ child <- tree $ children [[i ]]
1386
+ is_last <- i == length(tree $ children )
1387
+ margins <- set_margins(child , margins , has_background , has_top , has_bottom , if (is_last ) forced_margin else NULL )
1385
1388
}
1386
1389
for (i in seq_along(tree $ children )[- 1 ]) {
1387
1390
margins $ bottom [tree $ children [[i - 1 ]]$ element ] <- max(
0 commit comments