How can I mix Japanese and English in the same org-mode table (that uses fixed-width fonts)? Something like:

| m m m   m m m |      |
| はどう  デシウ |       |
| ハーフ           | ハーフ   |

won't align. Emacs simply counts the Japanese characters as one, when indeed they are more like 10% bigger.

Could the width of a column be set in pixels? I know that <10> would set the width, but that does not help, since it counts in terms of fixed-width letters.

The problem is basically how emacs aligns columns (using the font width).

  • Have you tried aligning the tables with C-c C-c while you are in a cell? I just pasted your example into an org-mode buffer, hit C-c C-c, and everything aligned nicely. – elethan Jan 25 '16 at 2:39
  • This is probably something that needs to be added to org-mode. It might be possible to achieve this using the :align-to display property, described in gnu.org/software/emacs/manual/html_node/elisp/…. – legoscia Jan 25 '16 at 12:25
  • @elethan: yes, some examples work with a certain combination of Western fonts, face size, and some Japanese text. Emacs tries to align examples as above and sometimes it gets it right. However, this is just a question of luck. In general, emacs is blind for this. – Quora Feans Jan 25 '16 at 12:57
  • Don't you need a monospaced font for this? In which case stackoverflow.com/q/3758139/4050592 should help provided you have a monospaced Japanese font you can use. – Andrew Swann Jan 29 '16 at 8:08

This depends on the fonts you are using. And I don't think Elisp has pixel level alignment capability.

Org calculate width of string with string-width instead of length. string-width returns 1 for ASCII and Half width CJK chars or 2 for Full width chars. Evaluate the following code will show you that:

(string-width "m")
(string-width "ハ")
(string-width "は")

Now, even though Org mode got the right answer from the sting property, and added pads around strings, it is the Emacs display engine's job to place where those bits go on the screen.

Emacs display engine gets font information from the underlying OS. To make the complex problem simple, let's say that, with your configuration, m's width is 5 pixels and "は" is 10. In this case they will be perfectly aligned because Org mode's assumption ("は" takes twice the width of "m") matches with the actual pixels on your screen.

Instead, if your fonts configuration has 7 pixel for "m" and 10 pixel for "は", the things won't match up. And there is nothing Org mode nor the Display engine can do. They did what they told, by your configuration, to do.

| improve this answer | |

You need to prepare the monospace font with 1:2 height-width aspect ratio, so called "narrow" font, such as Inconsolata. Most programmer's fonts have the aspect ratio of 3:5, or so called "wide" font, that can not be fit with Japanese font when used with org-mode tables.

Also, you must set your font height to be an even number. Otherwise, its width (half of height) wouldn't be an integer and would also cause problem on org-mode table alignment.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.