How can I format a column of numbers in an emacs org mode table?

I have a table in this form in emacs org-mode . Please, is there a way to format the numbers in columns 3 and 4 to align the decimal points vertically?

Note. Aside: I sorted the resulting file using the bash sort command and found that the extra | at the beginning of each row is counted as column 1, so for example, the column headed by OUTPUT is number 4 in this context.

 | CALL | CHAN | OUTPUT | INPUT | QTHR | LOCATION | NGR | REGION | CTCSS | KEEPER | Internet | | GB3AH | RB11 | 433.275 | 434.875 | JO02KP | East Dereham | TF94300990 | EAST ENG | 94.8 | G8PON | | | GB3AS | RV48 | 145.6 | 145 | IO84LS | Wigton,Cumbria | NY33724123 | N.ENG | 77 | G4KFN | | | GB3AG | RV58 | 145.725 | 145.125 | IO86ON | Forfar | NO48904170 | SCOT | 94.8 | GM1CMF | Echolink | | GB3AY | RV52 | 145.65 | 145.05 | IO75OR | Dalry | NS26605190 | SCOT | 103.5 | GM3YKE | | | GB3BA | RB01 | 433.025 | 434.625 | IO87SC | Banchory | NJ72150255 | SCOT | 67 | GM1XEA | | | GB3BD | RB06 | 433.15 | 434.75 | IO92RA | Ampthill | TL01303860 | SE ENG | 77 | G8MGP | | | GB3AA | 23cm | 1297 | 1291 | IO81RO | Alveston,Avon | ST62608820 | SW ENG | 118.8 | G4CJZ | | | GB3AI | RV55 | 145.6875 | 145.0875 | IO91QQ | Amersham | SU97089767 | SW ENG | 77 | G0RDI | Echolink | | GB3AL | RV59 | 145.7375 | 145.1375 | IO91QP | Amersham | SU95709550 | SW ENG | 77 | G0RDI | | | GB3AM | R50-13 | 50.84 | 51.34 | IO91QP | Amersham | SU95709550 | SW ENG | 77 | G0RDI | | 
+8
sorting bash emacs org-mode
source share
1 answer

Here are the steps:

  • This is an optional option to make things more visual. Cc} includes overlays for row and column numbers. The same combination turns off. Note that these are not changes to your buffer; they are just hints. You can do Cc - in the first row to see the column numbers.
  • Move the cursor to the OUTPUT column and insert a new column with CS-right .
  • Your cursor should now be in a new column. Enter $4=$3;%0.3f , i.e. Copy the third column to the fourth, and format it as a floating point with an accuracy of 3. Press return, and only one cell will fill. Press Cu Cc * to recount all cells. This can also be done using Cc Cc , with the cursor on the line #+TBLFM:
  • You can delete the old CM-left column if you want, and delete the table formula below.

UPDATE:

Thanks to input from @phils, here's an alternative way:

  • Move the cursor to any number in column 3, for example. 433.275 .
  • Press Cc = , the cursor moves to the minibuffer.
  • Enter $0;%0.3f and press return. Here $0 refers to the current column, $3 will also work if it were column 3.
  • Either press Cu Cc * anywhere in the document, or move the cursor to the line #+TBLFM: and press Cc Cc .
  • Repeat the same process for column 4.
+11
source share

All Articles