Text FormattingEnforcing lining Figures for Math Mode and Tables

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Bob_the_Topper
Posts: 15
Joined: Thu May 03, 2012 4:54 pm

Enforcing lining Figures for Math Mode and Tables

Post by Bob_the_Topper »

Hi!

I use cfr-lm to get oldstyle figures for regular text but they look bad in tables. Of course I could switch to lining figures manually (\lstyle or \textl) every single time but this is quite tedious. Also, lining figures are used automatically in math mode. Is there a way to enforce lining figures in tables too?

MWE:

Code: Select all

\documentclass{article}

\usepackage[%
  rm={oldstyle,proportional},%
  sf={oldstyle,proportional},%
  tt={oldstyle=false,proportional=false,monowidth}%
] {cfr-lm}

\begin{document}
Old style numerals (0123456789) look great in normal text, but sometimes lining figures (\textl{0123456789}) are more appropriate. For example in mathematical contexts, old style is just out of place ($123 + 456 \neq 789$).

In tables, too, old style figures look bad:
\begin{tabular}{l|r}
Name & Age \\
\hline
A & 12 \\
B & 23 \\
C & 64 \\
D & 67
\end{tabular}

Lining figures are much better, but have to be set manually:
{
\lstyle
\begin{tabular}{l|r}
Name & Age \\
\hline
A & 12 \\
B & 23 \\
C & 64 \\
D & 67
\end{tabular}
}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Enforcing lining Figures for Math Mode and Tables

Post by cgnieder »

You could use etoolbox to add lining figures to the {tabular} environment by adding these lines to your preamble:

Code: Select all

\usepackage{etoolbox}
\AtBeginEnvironment{tabular}{\lstyle}
Regards
site moderator & package author
Bob_the_Topper
Posts: 15
Joined: Thu May 03, 2012 4:54 pm

Re: Enforcing lining Figures for Math Mode and Tables

Post by Bob_the_Topper »

Works like a charm :)
Thanks!
Post Reply