typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
35.69k stars 953 forks source link

Matrix alignment and row spacing problems of mathematical models in tables #5489

Open whateverzpy opened 3 days ago

whateverzpy commented 3 days ago

Description

Look at the code and the image below

#table(
  columns: (
    auto,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
  ),align: horizon + center,rows: (auto, 3em, 3em, 3em),stroke: none,
  table.hline(),
  [$k$],
  table.vline(stroke: 0.6pt),
  [$bold(x)^((k))$],
  table.vline(stroke: 0.6pt),
  [$nabla f(bold(x)^((k)))$],
  table.vline(stroke: 0.6pt),
  [$bold(H)^((k))$],
  table.vline(stroke: 0.6pt),
  [$bold(d)^((k))$],
  table.vline(stroke: 0.6pt),
  [$lambda_k$],
  table.vline(stroke: 0.6pt),
  [$bold(s)^((k))$],
  table.vline(stroke: 0.6pt),
  [$bold(y)^((k))$],
  table.hline(stroke: 0.6pt),
  [$1$],[$mat(0;0)$],[$mat(-4;-8)$],[$mat(1,0;0,1)$],[$mat(4;8)$],[$5 / 34$],[$mat(10/17;20/17)$],[$mat(20/17;160/17)$],
  table.hline(stroke: 0.6pt),
  [$2$],[$mat(10/17;20/17)$],[$mat(-48/17;24/17)$],[$mat(2241/2210,-71/1105;-71/1105,147/1105)$],[$mat(192/65;-24/65)$],[$65 / 136$],[$mat(24/17;-3/17)$],[$mat(48/17;-24/17)$],
  table.hline(stroke: 0.6pt),
  [$3$],[$mat(2;1)$],[$mat(0;0)$],[],[],[],[],[],
  table.hline()
)

image This matrix is obviously not aligned with the other matrices in this row. However, when I don't specify line spacing, it seems like...

#table(
  columns: (
    auto,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
    0.125fr,
  ),align: horizon + center,stroke: none,
  table.hline(),
  [$k$],
  table.vline(stroke: 0.6pt),
  [$bold(x)^((k))$],
  table.vline(stroke: 0.6pt),
  [$nabla f(bold(x)^((k)))$],
  table.vline(stroke: 0.6pt),
  [$bold(H)^((k))$],
  table.vline(stroke: 0.6pt),
  [$bold(d)^((k))$],
  table.vline(stroke: 0.6pt),
  [$lambda_k$],
  table.vline(stroke: 0.6pt),
  [$bold(s)^((k))$],
  table.vline(stroke: 0.6pt),
  [$bold(y)^((k))$],
  table.hline(stroke: 0.6pt),
  [$1$],[$mat(0;0)$],[$mat(-4;-8)$],[$mat(1,0;0,1)$],[$mat(4;8)$],[$5 / 34$],[$mat(10/17;20/17)$],[$mat(20/17;160/17)$],
  table.hline(stroke: 0.6pt),
  [$2$],[$mat(10/17;20/17)$],[$mat(-48/17;24/17)$],[$mat(2241/2210,-71/1105;-71/1105,147/1105)$],[$mat(192/65;-24/65)$],[$65 / 136$],[$mat(24/17;-3/17)$],[$mat(48/17;-24/17)$],
  table.hline(stroke: 0.6pt),
  [$3$],[$mat(2;1)$],[$mat(0;0)$],[],[],[],[],[],
  table.hline()
)

image Multiple matrices will collide directly with the table edge line.

Reproduction URL

No response

Operating system

Windows

Typst version

whateverzpy commented 3 days ago

The reason for the seeming misalignment may have to do with the column width not being given enough. 70pt image 60pt image

laurmaedje commented 2 days ago

Minimized:

#table(
  columns: (
    2cm,
    2cm,
  ),
  $mat(1/1;2/2)$,
  $mat(3/3, 4/4; 5/123456, 1/123)$
)

Removing just one letter from "123456" or "123" changes things. Very odd.