General case
The following can be used to right-align all numbers (to align only integers or floats without exponents see here):
(require 'cl-seq)
(defconst my-string-number-regex
(concat "^[+-]?\\(?:[0-9]+\\(?:[.,][0-9]*\\)?\\(?:e[+-]?[0-9]+\\)?"
"\\|[.,][0-9]+\\(?:e[+-]?[0-9]+\\)?\\)$")
"Matches integers and floats with exponent.
This allows for leading and trailing decimal point, leading zeros in base,
leading zeros in exponent, + signs, and , as alternative decimal separator.")
(defun my-column-display-value-transformer (column-title value)
"Modifies the value to display in column view.
This modifies all numbers to align right."
(when (string-match-p my-string-number-regex value)
(let ((pos
(cl-position column-title org-columns-current-fmt-compiled
:test (lambda (x y) (equal x (car y))))))
(when-let
((target-width
(or (nth 2 (nth pos org-columns-current-fmt-compiled))
(aref org-columns-current-maxwidths pos)))
(vlength
(length value)))
(when (< vlength target-width)
(concat
(make-string (- target-width
vlength)
? )
value))))))
(setq org-columns-modify-value-for-display-function
#'my-column-display-value-transformer)
To instead right-align all values in the specific column "PRICE", replace the first when statement with (when (equal column-title "PRICE")
. To center add (/ ... 2)
around the (- ...)
in make-string
.
Column view uses org-columns-current-maxwidths
to set the column widths, but that varible is not updated yet when org-columns-modify-value-for-display-function
is called (it is called through org-columns--collect-values
in org-columns
one line before org-columns--set-widths
sets org-columns-current-maxwidths
). So to actually get the right alignment you have to either set a width in the column specification (%5PRICE
) or call org-columns-redo
directly after entering column view, for example by pressing r
or g
.
Summary values
Another solution works for the special case of the summary values of summary column types. For these can specify a format string which allows you to right align the displayed summary values. For example, if the largest number has 5 digits:
#+COLUMNS: %25ITEM %TODO %TAGS %PRICE{+;% 5d}
Unfortunately this only applies for summary types and also only for summary type entries which have at least one children to summarize over. So in the example given it would just apply in the heading row.