tabular numbers in tables, proportional in text

I'm using LuaTeX with a font that has proportional, lining and tabular numbers available.

Is it possible to set things up so tables automatically use tabular numbers - but proportional numbers are used in the text?

-
Could you add a minimal working example (MWE) so we can see your setup? Are you really using LuaTeX or rather LuaLaTeX? –  Qrrbrbirlbel Feb 23 '13 at 21:29

Yes, please provide an MWE so we know more about your specific situation. If for now we assume you're using fontspec like most people, what you're looking for is pretty easily done. I'd use the \AtBeginEnvironment from the etoolbox package to automatically invoke a font change at the begin of every tabular. This is a matter of just one line:

\AtBeginEnvironment{tabular}{\setmainfont[Numbers={OldStyle,Monospaced}]{Minion Pro}}


so, as figure style selection is already implemented in fontspec, there is no need for an additional package -- etoolbox is likely to get loaded by other common packages anyways (biblatex etc.). Here's the complete example:

\documentclass{article}
\usepackage{fontspec, etoolbox}

\setmainfont[Numbers={OldStyle,Proportional}]{Minion Pro}

\AtBeginEnvironment{tabular}{\setmainfont[Numbers={OldStyle,Monospaced}]{Minion Pro}}

\begin{document}
\raggedright
12345\\
00000

\begin{table}[h]
\begin{tabular}{l}
12345\\
00000\\
\end{tabular}
\end{table}

12345\\
00000
\end{document}


NB: besides its simplicity, another nice thing here is you can insert additional table formatting as well. E.g., I usually want my tables \footnotesize:

\AtBeginEnvironment{tabular}{\setmainfont{...}\footnotesize}

-
Great - apologies for the lack of MWE, but your answer has not only provided this but also the solution I was looking for. It really improves the look of my document too i.e. tables of numbers are easier to understand, and proportional numbers in the text just look better. Thanks! –  DavidC Feb 24 '13 at 17:21
It would be better if you just change the font features and not set a “new” main font: \addfontfeature{RawFeature=+tnum}. This also would keep the settings regarding lining and old-style numbers. Also, you do not need to change the tabular fix if you change the main font or switch to another font by other means. –  Qrrbrbirlbel Feb 24 '13 at 17:51
yep, that's an option as well. I chose not to suggest it, though, as (1) the \setmainfont method didn't seem to have any real drawbacks except being a tad less comfortable, and (2) the RawFeature method is a bit more low-level IMHO, making it something I'd suggest only to people who seem to know what they're doing :) –  Nils L Feb 24 '13 at 19:22
-- that said, if there are drawbacks when using \setmainfont locally that we're not aware of, let us know... –  Nils L Feb 24 '13 at 19:25
(Use @<user> to notify the author you respond to.) The RawFeatures are explained right alongside the textual options in Table 4 (p. 24) of the fontspec manual. The same effect can be achieved by \addfontfeatures{Numbers=Monospaced}, it keeps the lining/old-style setting as well. The drawback of \setmainfont is that you have to change the font in the fix manually, if you change the (actual) main font. If you export this fix in another file (say your own package) you may have to change the fix every time you switch documents. –  Qrrbrbirlbel Feb 24 '13 at 20:52

There is a package called tabfigures which I have not tried yet.

-