23

I found out about variable-pitch-mode through a thread here on StackOverflow, and it's very handy when writing in org-mode, easier on the eyes and everything. But using tables in org is close to worthless when using proportional fonts. And being able to use tables is one of the strengths with org-mode :-(

Is there any way to have proportional fonts for text, headings etc. but a monospace font for tables in org-mode?

Community
  • 1
  • 1
monotux
  • 3,657
  • 28
  • 30

2 Answers2

23

See if this works,

(set-face-attribute 'org-table nil :inherit 'fixed-pitch)

You may use C-u C-x = to see which face is in effect at a particular point.

huaiyuan
  • 26,129
  • 5
  • 57
  • 63
  • Awesome! Works just like I want it :) – monotux Sep 23 '10 at 07:03
  • 2
    How did you find out that the table was 'org-table ? I'd like to use this solution on the output of the SQL buffer – EoghanM May 27 '11 at 15:16
  • 1
    @EoghanM: If "C-u C-x =" didn't give the name of "face" or "font-lock-face", then the face in effect would be "default", by default. The above method only applies when the buffer is highlighted in font-lock-mode or tagged otherwise in different faces. – huaiyuan May 28 '11 at 05:19
  • 1
    For some reason, although running `describe-face` tells me that the font should be inheriting from ‘fixed-pitch (or just ‘default in my case), the displayed font is still ‘variable-pitch… – xji May 24 '15 at 09:18
  • Never mind seems to be `buffer-local-theme` package causing the bug. – xji May 28 '15 at 08:29
  • Follow-up question: how can I make this also affect links inside tables? – Timm Sep 07 '16 at 09:33
12

This code will make tables and ascii art and source code blocks to be displayed in monospace font, while preserving other font attributes for tables (such as color blue) and so on. Code is based on the other answer, the only difference is preservation.

(defun my-adjoin-to-list-or-symbol (element list-or-symbol)
  (let ((list (if (not (listp list-or-symbol))
                  (list list-or-symbol)
                list-or-symbol)))
    (require 'cl-lib)
    (cl-adjoin element list)))

(eval-after-load "org"
  '(mapc
    (lambda (face)
      (set-face-attribute
       face nil
       :inherit
       (my-adjoin-to-list-or-symbol
        'fixed-pitch
        (face-attribute face :inherit))))
    (list 'org-code 'org-block 'org-table 'org-block-background)))

If you'd like to learn how this works and how to apply this to other situations (such as Info mode), read my post on the subject

Jisang Yoo
  • 3,670
  • 20
  • 31
  • For some reason, although running `describe-face` tells me that the font should be inheriting from ‘fixed-pitch (or just ‘default in my case), the displayed font is still ‘variable-pitch… – xji May 24 '15 at 09:18
  • Never mind seems to be `buffer-local-theme` package causing the bug. – xji May 28 '15 at 08:29