7

I use org-mode daily for all sorts of things, and I like variable-width fonts for reading text which makes up the majority of my files. But for tables to be correctly aligned, a fixed-width font it necessary. Is it possible to configure emacs to show org-mode tables in a fixed-with font and the rest of the buffer in a variable-width font?

I understand the typical question is not: "Is X possible in emacs?" but rather "How do I do X in emacs?" so I'm optimistic, but haven't found an answer on Google or SO yet...

Matthew Gilliard
  • 9,298
  • 3
  • 33
  • 48

2 Answers2

5

You can have multiple fonts in a buffer (C-h C-a to see an example).

You can customize the font family of any face in emacs, so you can have variable and fixed width sizes fonts.

Then you can use font-lock-add-keywords (for example) in org-mode-hook to instruct font-lock to use a face with fixed width the regular expression that matches rows of a table (I think it would be something like "\s*|.*", but maybe I am oversimplifying)

Matthew Gilliard
  • 9,298
  • 3
  • 33
  • 48
juanleon
  • 9,220
  • 30
  • 41
  • This is great. For the specific problem I was having (fixed-width in org-tables) the answer linked to by huaiyuan is simpler. But this answer is more widely applicable and useful in other situations. Thanks. – Matthew Gilliard Sep 18 '13 at 15:16
0

For a more current solution you can check out mixed-pitch mode. It takes care of adjusting fonts not only tables and src-blocks in org-mode but also takes care of fonts in other text modes as well (LaTeX mode, for example).

Daniel
  • 11,332
  • 9
  • 44
  • 72