Fix figure centering (#4276)

Co-authored-by: PgBiel <9021226+PgBiel@users.noreply.github.com>
This commit is contained in:
Laurenz 2024-05-29 15:17:05 +02:00 committed by GitHub
parent 06433bc95f
commit e6739ecc2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 8 deletions

View File

@ -14,8 +14,8 @@ use crate::introspection::{
Count, Counter, CounterKey, CounterUpdate, Locatable, Location,
};
use crate::layout::{
Alignment, BlockElem, Em, HAlignment, Length, OuterVAlignment, PlaceElem, VAlignment,
VElem,
AlignElem, Alignment, BlockElem, Em, HAlignment, Length, OuterVAlignment, PlaceElem,
VAlignment, VElem,
};
use crate::model::{Numbering, NumberingPattern, Outlinable, Refable, Supplement};
use crate::text::{Lang, Region, TextElem};
@ -317,11 +317,7 @@ impl Show for Packed<FigureElem> {
}
// Wrap the contents in a block.
realized = BlockElem::new()
.with_body(Some(realized))
.pack()
.spanned(self.span())
.aligned(Alignment::CENTER);
realized = BlockElem::new().with_body(Some(realized)).pack().spanned(self.span());
// Wrap in a float.
if let Some(align) = self.placement(styles) {
@ -340,7 +336,10 @@ impl ShowSet for Packed<FigureElem> {
fn show_set(&self, _: StyleChain) -> Styles {
// Still allows breakable figures with
// `show figure: set block(breakable: true)`.
BlockElem::set_breakable(false).wrap().into()
let mut map = Styles::new();
map.set(BlockElem::set_breakable(false));
map.set(AlignElem::set_alignment(Alignment::CENTER));
map
}
}

BIN
tests/ref/figure-align.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 926 B

View File

@ -23,6 +23,13 @@ We can clearly see that @fig-cylinder and
caption: [The complex table.],
) <tab-complex>
--- figure-align ---
#show figure: set align(start)
#figure(
rect[This is \ left],
caption: [Start-aligned]
)
--- figure-table ---
// Testing figures with tables.
#figure(
@ -37,6 +44,7 @@ We can clearly see that @fig-cylinder and
--- figure-theorem ---
// Testing show rules with figures with a simple theorem display
#show figure.where(kind: "theorem"): it => {
set align(start)
let name = none
if not it.caption == none {
name = [ #emph(it.caption.body)]