mirror of
https://github.com/typst/typst
synced 2025-05-17 02:25:27 +08:00
Initial support for breakable figures (#1121)
This commit is contained in:
parent
e8de8a49c5
commit
a8728be9b0
@ -70,9 +70,14 @@ use crate::visualize::ImageElem;
|
|||||||
/// )
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// If your figure is too large and its contents are breakable across pages
|
||||||
|
/// (e.g. if it contains a large table), then you can make the figure breakable
|
||||||
|
/// across pages as well by using `#show figure: set block(breakable: true)`
|
||||||
|
/// (see the [block]($func/block) documentation for more information).
|
||||||
|
///
|
||||||
/// Display: Figure
|
/// Display: Figure
|
||||||
/// Category: meta
|
/// Category: meta
|
||||||
#[element(Locatable, Synthesize, Count, Show, Refable)]
|
#[element(Locatable, Synthesize, Count, Show, Finalize, Refable)]
|
||||||
pub struct FigureElem {
|
pub struct FigureElem {
|
||||||
/// The content of the figure. Often, an [image]($func/image).
|
/// The content of the figure. Often, an [image]($func/image).
|
||||||
#[required]
|
#[required]
|
||||||
@ -254,12 +259,18 @@ impl Show for FigureElem {
|
|||||||
// We wrap the contents in a block.
|
// We wrap the contents in a block.
|
||||||
Ok(BlockElem::new()
|
Ok(BlockElem::new()
|
||||||
.with_body(Some(realized))
|
.with_body(Some(realized))
|
||||||
.with_breakable(false)
|
|
||||||
.pack()
|
.pack()
|
||||||
.aligned(Axes::with_x(Some(Align::Center.into()))))
|
.aligned(Axes::with_x(Some(Align::Center.into()))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Finalize for FigureElem {
|
||||||
|
fn finalize(&self, realized: Content, _: StyleChain) -> Content {
|
||||||
|
// Allow breakable figures with `show figure: set block(breakable: true)`.
|
||||||
|
realized.styled(BlockElem::set_breakable(false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Count for FigureElem {
|
impl Count for FigureElem {
|
||||||
fn update(&self) -> Option<CounterUpdate> {
|
fn update(&self) -> Option<CounterUpdate> {
|
||||||
// If the figure is numbered, step the counter by one.
|
// If the figure is numbered, step the counter by one.
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 70 KiB |
@ -101,4 +101,11 @@ We can clearly see that @fig-cylinder and
|
|||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
]
|
]
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test breakable figures
|
||||||
|
#set page(width: 200pt, height: 6em)
|
||||||
|
#show figure: set block(breakable: true)
|
||||||
|
|
||||||
|
#figure(table[a][b][c][d][e], caption: [A table])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user