Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align numbers at dot within table columns #170

Open
tv42 opened this issue Mar 22, 2023 · 5 comments
Open

Align numbers at dot within table columns #170

tv42 opened this issue Mar 22, 2023 · 5 comments
Labels
feature request New feature or request layout Related to layout, positioning, etc.

Comments

@tv42
Copy link

tv42 commented Mar 22, 2023

Hi. I have a spreadsheet-like report that looks like

category cost
widgets 42.00
gadgets 1.10
thingies 890.00

I would like to align the numbers so the periods are vertically aligned.
This seems perhaps possible already, but not simple. Something like a loop and manually calculating max width over of both sides of the period-split number, and then a for loop, etc..

@tv42 tv42 changed the title Align numbers at dot wishlist: Align numbers at dot Mar 23, 2023
@ghost
Copy link

ghost commented Mar 24, 2023

I would just right align:

#set text(font: "Segoe UI")

#table(
   align: right,
   columns: 2,
   [*category*], [*cost*],
   [widgets], [#"42.00"],
   [gadgets], [#"1.10"],
   [thingies], [#"890.00"]
)

or you could do something like this:

align: (col, row) => if col == 1 and row >= 1 { right } else { center },

if you really want to nitpick, you can also mess with pad:

https://typst.app/docs/reference/layout/pad

@owiecc
Copy link
Sponsor Contributor

owiecc commented Mar 24, 2023

align: decimal.dot or align: decimal.comma would be great.

Ideally also an arbitrary alignment mark align: "=" so that the equations or numbers do not need to be modified.

\begin{align} 
2x - 5y &= 8 \\ 
3x   9y &= 4
\end{align}

@reknih reknih changed the title wishlist: Align numbers at dot Align numbers at dot within table columns Apr 4, 2023
@reknih reknih added feature request New feature or request layout Related to layout, positioning, etc. labels Apr 4, 2023
@Munchotaur
Copy link

I think this should be a built-in feature. It's fairly common in some end-uses to have differing numbers of digits both before and after the point, as you move down the columns of characteristics from, say, small to large product models. In certain page layout apps I'd just centre align then pad the whole column with figure-width spaces, assuming a font with fixed-width digits/decimal point. But a built-in markup for decimal (or arbitrary character) alignment makes things easier. As indeed do figure spaces.

@luewolf
Copy link

luewolf commented Aug 24, 2024

I think, by default, the decimal delimiter that's used for alignment should depend on the context language.

Also, it should be compatible with existing cell alignments:

|left num     | center num  |    right num|
|_____________|_____________|_____________|
|100.359      |   100.359   |      100.359|
| 99.23       |    99.23    |       99.23 |
| 21.445      |    21.445   |       21.445|

Non-number symbols should be aligned on their own axis. Not sure how to handle " " and "-". Maybe that should be configurable:

|       prefix|       suffix|                      sign?|
|_____________|_____________|___________________________|
|    > 100.359|   100.359 mm|     -100.359|     -100.359|
|    ≥  99.23 |    99.23  µm|      -99.23 |     - 99.23 |
|    ~  21.445|    21.445 nm|      -21.445|     - 21.445|

@Munchotaur
Copy link

Munchotaur commented Aug 24, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request layout Related to layout, positioning, etc.
Projects
None yet
Development

No branches or pull requests

5 participants