让中英混杂的orgmode table对齐

orgmode的表格简单实用,甚至具有电子表格功能,除此之外,它还是column view的表现形式。然而当中英文混杂时,如果不做特殊处理,表格不对齐,看起来一团糟。

unaligned orgmode table

不太完美的解决方法依然是使用中文大字英文小字,只不过为Emacs 23.2需使用不同的字号(英文12中文15)。英文设置如下

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "#ffffff" :foreground "#000000"
                         :inverse-video nil :box nil :strike-through nil :overline nil
                         :underline nil :slant normal :weight normal :height 120
                         :width normal :foundry "unknown" :family "Liberation Mono")))))

中文设置如下:

(if (and (fboundp 'daemonp) (daemonp))
    (add-hook 'after-make-frame-functions
              (lambda (frame)
                (with-selected-frame frame
                  (set-fontset-font "fontset-default"
                                    'chinese-gbk "WenQuanYi Micro Hei Mono 15"))))
  (set-fontset-font "fontset-default" 'chinese-gbk "WenQuanYi Micro Hei Mono 15"))

另外,为了column view能够在daemon模式下正常显示,还需要如下代码:

(defun wl-org-column-view-uses-fixed-width-face ()
  ;; copy from org-faces.el
  (when (fboundp 'set-face-attribute)
    ;; Make sure that a fixed-width face is used when we have a column table.
    (set-face-attribute 'org-column nil
                        :height (face-attribute 'default :height)
                        :family (face-attribute 'default :family))))

(when (and (fboundp 'daemonp) (daemonp))
  (add-hook 'org-mode-hook 'wl-org-column-view-uses-fixed-width-face))

使用这些补丁(在Ubuntu 10.04和Fedora 13上测试成功)之后,表格能够对齐了,瑕疵是中文字过大。

aligned orgmode table