2

I can't align colum data on the decimal point:

data = { {1, 45000.5, 27500.}, {2, 22500., 18333.3},
         {3, 15000., 13750.}, {4, 11250., 11000.},
         {5, 9000., 9166.67} }

Grid[data, {Alignment->".", Frame-> All}]

Here is a screen capture of the result as seen in the Notebook:

enter image description here

I tried many syntax variations for the Alignment option. And I also tried TextGrid instead of a plain Grid and TableForm alongside TableAlignements. I never obtained a table whose values are aligned on the decimal point.

TableForm[data, TableAlignments->"."]
Grid[data, {Alignment->".", Frame-> All}]
Grid[data, {Alignment->{".","."}, Frame-> All}]
Grid[data, {Alignment->{{".","."}}, Frame-> All}]

I saw a seven-years-old question that states there is an issue with alignment to the decimal point. But as far as I understood it, this is only triggered when using ItemSize. Not when using Alignment only.

Explicitly using a NumberForm and Right aligning the data is kind of a workaround, but this is not entirely satisfying.

Any thoughts or suggestions to fix my issue?


It appears the issue is with the Notebook: when I export the result as an image, data are properly aligned:

enter image description here

How to ensure the table is properly displayed in the Notebook too?

FWIW, I'm using Wolfram Cloud in a Firefox 69.02 browser on Linux

Sylvain Leroux
  • 1,509
  • 5
  • 15
  • Sylvain, I can't reproduce your problem in the desktop version of MMA (v12, Win10-64), so the problem seems to be with the cloud version only. – MarcoB Dec 09 '19 at 18:36
  • Thanks @Marco. Indeed it seems related to the Cloud Notebook and/or my Browser. I've added the relevant tag to the question. FWIW, exporting the table either as bitmap or PDF will display the data with proper alignment. – Sylvain Leroux Dec 09 '19 at 18:39
  • 2
    Grid alignment at characters is not supported in cloud notebooks yet, but coming soon (maybe Cloud 1.55 in 2020 Q1). – Jan Pöschko Dec 13 '19 at 09:53

1 Answers1

1

As a workaround, wrapping the grid inside a Rasterize function displays the table with proper formatting--at the expanse of making the result uneditable:

Rasterize[Grid[data, {Alignment->".", Frame-> All}]]

text vs. rasterized version of output

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Sylvain Leroux
  • 1,509
  • 5
  • 15
  • 1
    Yes, that would be an OK workaround for now. Just FYI, you can also convert a cell to an image using the cell gear menu (next to the cell bracket in cloud notebooks): Convert to > Image. You can also use the cell option CloudRenderingMethod->"Bitmap" to force rendering as a bitmap. – Jan Pöschko Dec 13 '19 at 09:50
  • Thanks for the info @Jan. – Sylvain Leroux Dec 13 '19 at 13:05