Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like Emacs/AUCTeX to show the contents of tabular environments in a fixed-width font, so table boundaries line up. Is it possible to set the font face of specific environments like this?

The verbatim environment shows its contents in a fixed-width font (in Emacs, not the typeset output). I tried adding tabular to the variable LaTeX-verbatim-environments, which works but then all the colour highlighting is gone.

Also, it would be good to show comment environments in fixed-width for use with Org-mode tables, but adding comment to LaTeX-verbatim-environments has no effect.

Of course I could just use a fixed-width font, but I would rather have a nice font for the majority of the text.

share|improve this question
    
Are you using custom font configuration in Emacs? Emacs uses a fixed width font per default. –  N.N. Feb 15 '13 at 18:08
    
Yes, I was using variable-pitch-mode to show the majority of the text in non-monospaced fonts for easy reading. –  RCL Feb 17 '13 at 22:07
    
You might want to include the relevant configuration in your question by editing it. –  N.N. Feb 18 '13 at 6:25
add comment

1 Answer 1

Emacs uses a fixed width font per default, so you should not have to set it for a specific environment. I assume you use a custom font configuration.

Rather than changing fonts for specific environments you can use align commands to format tabular data neatly. For example, select the tabular data and do M-x align-all-strings and then it asks "Align by: ", type & and press Enter. M-x align-entire also seems to work nicely and it guesses which character to align by so you do not have to input one.

For example if you the following:

\begin{tabular}{ l l l }
  cow & bull & horse \\
  elephant & shark & panda \\
  killer shark & tiger & giraffe
\end{tabular}

If you then select the tabular data and do M-x align-all-strings RET & RET you get the following:

\begin{tabular}{ l l l }
  cow          & bull  & horse \\
  elephant     & shark & panda \\
  killer shark & tiger & giraffe
\end{tabular}

Note that the align commands works in any Emacs mode, e.g. they work both in AUCTeX and Org-mode. Also note that, compared to configuring fonts in Emacs, also will improve readability of tabular data for other people viewing your file. Finally, note that if you use another editor it might also be capable of doing this sort of alignment, e.g. for vim see the description of Tabular in this description of vim tricks.

share|improve this answer
    
Thanks for your answer. The problem was that, like you say, I was using a custom font setting (variable-pitch-mode) but wanted to cancel this change for certain environments which need fixed-pitch fonts to show the alignment properly. The easy solution would be to forget variable-pitch-mode but I was trying to avoid that. –  RCL Feb 17 '13 at 22:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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