5

Is there a way that I can change font type of some numbers into math font without calling the math mode?

Basically I have a some integers in table that needs to be separated by commas. For example, say the number is 55,000. This number is entered as text under multicolumn environment so it looks different from other numbers in the table (which are in math mode). The table is set up so that \num cannot be used and I can only do code $55{,}000$ to keep the font type consistent.

However, I cannot automate the process of adding {,} in the program that I use to create tex files. So I have to find a way to just change the font type for the line of text 55,000.

\documentclass[12pt,letterpaper,fleqn]{article}
\usepackage{booktabs}

\usepackage{palatino}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{@{} l *{5}{d{2.5}} @{}}
\toprule
& \mc{AA}  & \mc{AA}  & \mc{AA}  & \mc{BB}  & \mc{CC} \\
& \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} \\
\midrule
X & -0.333^{***} & -0.222^{***} & -0.776^{***} & -0.333^{***} & -0.662^{***} \\ 
  & (0.003) & (0.002) & (0.026) & (0.048) & (0.001) \\ 
Y & & -0.004  & & \\ 
  & & (0.008) & & \\ 
Z & 0.111 & 0.122 & 0.123 & 0.122 & 0.133 \\ 

Obs & \mc{$55,000$} & \mc{56,000} & \mc{$56{,}000$} & \mc{$56{,}000$}  & \mc{$56{,}000$} \\ 
FE & & & \mc{Yes} & \mc{Yes} & \mc{Yes} \\
F-stat & & 0.225 & 0.221 & 0.222 & 0.220 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

Here is the output: enter image description here

Please look at the Obs row. I am using three different methods in column (1), (2), and (3) to (5). Column (1) has different font type; Column (2) has bad spacing for the comma; Column (3)-(5) is good but cannot be automated in a statistical software such as Stata. Any alternative way to code (3)-(5)?

  • Real quick: If you're using Palatino as the text-mode font, do you want to use it as the math-mode font as well? Or do you want to keep using Computer Modern for math-mode material? Please advise. – Mico Jul 11 '18 at 20:12
  • @Mico That is a great question... I prefer to keep the computer modern for math-mode, but the other way around should work too. – James H Jul 11 '18 at 20:29
  • I'll post an answer that works with Palatino as both the text font and the math font. Aside: Palatino is much "darker" than Computer Modern. Trying to mix and match Palatino text and Computer Modern math is pretty much an exercise in futility. – Mico Jul 11 '18 at 20:34
4

Since you're using Palatino as the text font, I think you'd be well-advised to use it for math material as well. Don't load the palatino package, though, as it provides only a text font. Instead, load the newpxtext and newpxmath packages.

Note that you can then write \mc{55,000} and \mc{56,000} and not have to worry about how to convince TeX not to insert a bit of extra whitespace after the commas that act as thousands-separators.

enter image description here

\documentclass[12pt,letterpaper,fleqn]{article}
\usepackage{booktabs}
\usepackage{newpxtext,newpxmath}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}

\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{l *{5}{d{2.5}}}
\toprule
& \mc{AA}  & \mc{AA}  & \mc{AA}  & \mc{BB}  & \mc{CC} \\
& \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} \\
\midrule
text mode/good: & \mc{55,000} & \mc{56,000} & \mc{56,000} & \mc{56,000}  & \mc{56,000} \\ 
math mode/bad: & \mc{$55,000$} & \mc{$56,000$} & \mc{$56,000$} & \mc{$56,000$}  & \mc{$56,000$} \\
math/tedious: & \mc{$55{,}000$} & \mc{$56{,}000$} & \mc{$56{,}000$} & \mc{$56{,}000$}  & \mc{$56{,}000$} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
  • Thank you Mico! This is a very simple and fast solution. Just curious, do other font types have this too? Like tgpagella or times? – James H Jul 11 '18 at 21:05
  • Update: I just tried this and it seems to conflict with a math package? Error: amsthm.sty (line 430) LaTeX Error: Command \openbox already defined. – James H Jul 11 '18 at 21:07
  • @JamesH - As far as I know, times and tgpagella provide only text fonts -- clones of Times Roman and Palatino, respectively. (And don't even think about mixing and matching Times Roman and Palatino -- unless, of course, you want to create a document that looks suspiciously like a ransom note...) Please advise whether you load amsthm before or after newpxmath. – Mico Jul 11 '18 at 21:13
  • 1
    I had amsthm after and just tried moving it before newpxmath -- the error disappears! – James H Jul 11 '18 at 21:15
  • @JamesH - The Times-Roman equivalent of the newpxtext/newpxmath pair of packages is called newtxtext/newtxmath. – Mico Jul 11 '18 at 21:16

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.