# lining figures in tables and math, old style figures in text

I’m using TeXLive 2012, up to date on Ubuntu 12.10. When I use the libertine package with the option osf and newtxmath for math fonts, I get oldstyle numbers everywhere, but I only want to use them in the body, not in tables or math mode. Here’s picture of the problem and an MWE :

\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{textcomp}
\usepackage[osf]{libertine}
\usepackage{amsmath, amsthm}
\usepackage[cmintegrals, cmbraces, libertine]{newtxmath}
\usepackage[version=3]{mhchem}

\begin{document}
Old style numbers belong in text 0123456789.
Not in equations:
$$\cee{C6H12O6 + 6O2 -> 6CO2 ^ + 6H2O ^ + \text{heat} ^}$$
Nor in tables:
\begin{table}[!htb]
\begin{tabulary}{\textwidth} {LCCCCR}
\toprule
climate &
species &
mean &
median &
standard deviation &
number of experiments \\
\midrule
1 & \textit{Picea abies}  & 20,3699   & 20,0335   & 4,453 & 30 \\
\bottomrule
\end{tabulary}
\caption{mean, median and standard deviation}
\label{tab:mean}
\end{table}

\end{document}

• For mhchem's formulas: \mhchemoptions{textfontcommand=\libertineLF} May 15, 2013 at 0:46
• That works only if I use LuaLaTex, not with pdfTeX May 15, 2013 at 2:04
• related?: disabling Libertine old style figures in specific places, tex.stackexchange.com/questions/9170 May 15, 2013 at 10:29

The libertine package per default has the options lining and tabular activated. In normal text you usually want proportional and oldstyle, though.

\usepackage[oldstyle,proportional]{libertine}


You don't want to set them as package options, though, but only after newtxmath has been loaded to get lining figures in math. This could be done by defining \libertine@figurealign to an empty definition (with pdfLaTeX) or to Proportional (with XeLaTeX or LuaLaTeX) and call \libertineOsF afterwards:

\usepackage{libertine}
\usepackage[cmintegrals, cmbraces, libertine]{newtxmath}
\makeatletter
\AtBeginDocument{\def\libertine@figurealign{}\libertineOsF}
\makeatother


If you now want that mhchem has lining numbers in text mode, too, you have to set its font option:

\mhchemoptions{textfontcommand=\libertineLF}


In a table you usually want libertine's defaults back. That could be done by redefining \libertine@figurealign to T (it's definition is empty for proportional figures) when compiling with pdfLaTeX or to Monospaced (vs. Proportional) with XeLaTeX or LuaLaTeX, and calling the switch \libertineLF afterwards. For convenience one could define a command \libertineTabular:

\makeatletter
\newcommand\libertineTabular{\def\libertine@figurealign{T}\libertineLF}
\makeatother


This newly defined command should be only used inside the {table} environment or, to be more precise, locally if you don't want to switch to tabular figures for the whole document.

\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{textcomp}
\usepackage{amsmath, amsthm}
\usepackage{libertine}
\usepackage[cmintegrals, cmbraces, libertine]{newtxmath}
\usepackage[version=4]{mhchem}
\mhchemoptions{textfontcommand=\libertineLF}

\makeatletter
\AtBeginDocument{\def\libertine@figurealign{}\libertineOsF}
\newcommand\libertineTabular{\def\libertine@figurealign{T}\libertineLF}
\makeatother

\begin{document}
Old style numbers belong in text 0123456789. \ce{C6H12O6 + 6O2 -> 6CO2 ^ + 6H2O ^ + \text{heat} ^}
Not in equations:
$$\ce{C6H12O6 + 6O2 -> 6CO2 ^ + 6H2O ^ + \text{heat} ^}$$
Nor in tables.

\begin{table}[!htb]
\caption{mean, median and standard deviation}
\label{tab:mean}\libertineTabular
\begin{tabulary}{\textwidth} {LCCCCR}
\toprule
climate & species & mean &  median & standard deviation & number of experiments \\
\midrule
1 & \textit{Picea abies}  & 20,3699   & 20,0335   & 4,453 & 30 \\
2 & \textit{Picea abies}  & 23,9864   & 12,6398   & 7,236 & 98 \\
\bottomrule
\end{tabulary}
\end{table}

$a^2 + b^2 = c^2 \qquad 1234567890$
Old style numbers belong in text 0123456789.

\end{document}

• That works as expected, but with pdftex mhchem doesn’t respect the \mhchemoptions{textfontcommand=\libertineLF} command. I found another way from the newtx doc and will edit it in your answer if that’s ok. May 15, 2013 at 12:16
• @jon I can't test now but I really would be surprised if you'd get lining tabular figures with only \AtBeginDocument{\libertineOsF} May 15, 2013 at 16:13
• @jon the tricky part which isn't solved with your simple solution I just checked) is to get proportional figures in the text but monospaced figures in the table. May 15, 2013 at 17:53
• Hmm, I wasn't thinking about proportional figures.... But couldn't we use etoolbox to hook into the table environment (\AtBeginEnvironment{table}{\libertineTabular}) to make it easier to keep all table environments consistent?
– jon
May 15, 2013 at 20:24
• @jon yes I thought about that, too, and if all tables should have them I'd say this would be the way to go. May 15, 2013 at 20:44
1. Use \usepackage{libertine}, and immediately after \begin{document}, use \libertineOsF.
2. Immediately after \begin{table}[..], use \libertineLF.
• Better: \usepackage{libertine} and \AtBeginDocument{\libertineOsF}. You don't need to do all the switching back and forth.
– jon
May 15, 2013 at 5:00

As noted by @cgnieder the default appearance of numbers for the main text should be set to proportional and osf (old style figures). The chemistry equations should get proportional lining figures. Finally, tables should contain tabular figures (equal width), but personally I think old style figures are fine in a table.

In the following code I define three font switching commands that can be used to set the desired style on certain places. Then I set the styles as described in the previous paragraph. The main difference to cgnieder's answer is that I set tabular figures for all tabulary tables, without the need to specify that on each table by hand.

\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{textcomp}
% \usepackage{libertine}               %% to have tabular (lining) figures in chemistry equations
\usepackage[proportional]{libertine} %% to have proportional (lining) figures in chemistry equations
\usepackage{amsmath, amsthm}
\usepackage[cmintegrals, cmbraces, libertine]{newtxmath}
\usepackage[version=3]{mhchem}

\makeatletter
\newcommand\libertineTLF{\def\libertine@figurealign{T}\libertineLF}
% \newcommand\libertinePLF{\def\libertine@figurealign{}\libertineLF}    %% not needed
\newcommand\libertineTOsF{\def\libertine@figurealign{T}\libertineOsF}
\newcommand\libertinePOsF{\def\libertine@figurealign{}\libertineOsF}
\makeatother

%% to have proportional old style figures in the main text
\AtBeginDocument{\libertinePOsF}

%% to have lining figures in chemistry equations;
%% to switch between tabular and  proportional lining figures, use the proportional package option of libertine
\mhchemoptions{textfontcommand=\libertineTLF}

%% to have tabular figures in all tabulary environments
\usepackage{etoolbox}
\makeatletter
\pretocmd{\TY@tabular}{\libertineTOsF}{}{}  %% tabular old style figures
% \pretocmd{\TY@tabular}{\libertineTLF}{}{}   %% tabular lining figures
\makeatother

\begin{document}
Old style proportional width numbers belong in text 0123456789.
Not in equations (does not make sense chemically):
\begin{align}
\cee{C6H12O6 + 6666O2 & -> 6666CO2 ^ + 6666H2O ^ + \text{heat} ^} \\
\cee{C6H12O6 + 1111O2 & -> 1111CO2 ^ + 1111H2O ^ + \text{heat} ^}
\end{align}
Nor in tables:
\begin{table}[!htb]
\begin{tabulary}{\textwidth} {LCCCCR}
\toprule
climate &
species &
mean &
median &
standard deviation &
number of experiments \\
\midrule
1 & \textit{Picea abies}  & 20,3699   & 20,0335   & 4,453 & 30 \\
1 & \textit{Picea abies}  & 20,3699   & 11,1111   & 4,453 & 30 \\
9 & \textit{Picea abies}  & 20,3699   & 99,9999   & 4,453 & 30 \\
\bottomrule
\end{tabulary}
\caption{mean, median and standard deviation}
\label{tab:mean}
\end{table}
\end{document}


• Considering that the numbers in the table are probably scientific data I'd think it's rather unusual to use oldstyle figures for them... one could of course use siunitx for those and set siunitx to use lining figures which could make a specific table setup for the figures redundant... May 15, 2013 at 16:39
• @cgnieder I know. I read your objection before, that is why I put a way to change to lining figures in the code. However, I've never seen a convincing explanation why tables should contain lining figures. I think OsF's are easier to read.
– mafp
May 15, 2013 at 16:55
• Maybe that's it: I for my part find oldstyle figures quite distracting when comparing data. Maybe that's just because I'm used to lining figures there. I'm curious what Tufte has to say to this matter. May 15, 2013 at 17:04
• As far as I remember, Tschichold recommends using old style figures throughout the text, thus in footnotes and tables. But the table in my MWE is rather short, the original extends over the whole page and I think it looks quite bumpy and uneven. Lining figures look much cleaner. May 15, 2013 at 19:25
• @TobiasSchula Maybe it is just a matter of taste. But I prepared the code for lining figures, too, just uncomment the other \pretocmd{...} line, and comment the one currently active.
– mafp
May 15, 2013 at 19:36