5

This is a follow up question from Using old style fonts of palatino (mathpazo) in math mode. The original problem has been solved using siunitx instead of dcolumn. However, the problem is that I am using mathpazo with osf as my main body font and eulervm as my math font. With siunitx used to decimal align tables this results in []() symbols being drawn in the math font, but the digits being drawn in the text font, as the following MWE example illustrates.

Is it possible to draw the symbols in the normal text font or redefine the mathfont for S columns completely?

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage[osf]{mathpazo}
\usepackage[euler-digits]{eulervm}

% For Tables created by estout
\newcommand{\sym}[1]{\ensuremath{^{#1}}} % for symbols in Table
\usepackage{siunitx}
\sisetup{ detect-mode, 
          group-digits            = false ,
          input-signs             = ,
          input-symbols           = ()[]-+ ,
          input-open-uncertainty  = ,
          input-close-uncertainty = ,
          table-align-text-post   = false 
        }
\begin{document}
\begin{tabular*}{\textwidth}{
    l @{\extracolsep\fill} *{2}{S[table-format=4.4]} @{}}
\toprule
\multicolumn{1}{@{}l}{\emph{Age}}  \\[0.5ex]
18--24 &   [-1360.228]\sym{*}  &  -1371.941\sym{*}  \\
       &       (6.915)         &    (-7.953)        \\
25--34 &     -219.216          &   -240.271         \\
       &     (514.894)         &   (515.348)        \\
35--44 &     -310.715          &   -311.438         \\
       &     (485.780)         &   (486.013)        \\
55$+$  &       -5.135          &     [2.656]        \\
       &      (53.267)         &   (533.875)        \\
\bottomrule
\end{tabular*}
\end{document}

Edit: Thanks to David the problem has been solved including a fix for amsmath and extending to XeTeX. On a side note, the command for * generated by estoutshould now be simply plain text:

\newcommand{\sym}1{#1} % for symbols in Table

\newcommand{\sym}[1]{\rlap{$#1$}} % Thanks to David Carlise again.
Jörg
  • 7,653

1 Answers1

6

If siuintx doesn't have customisation for this, one way, without having to mess with the math font layout, is to make the brackets switch to text mode, either globally, or, as here, just for a single envrironment

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage[osf]{mathpazo}
\usepackage[euler-digits]{eulervm}


% For Tables created by estout
\newcommand{\sym}[1]{\ensuremath{^{#1}}} % for symbols in Table
\usepackage{siunitx}
\sisetup{ detect-mode, 
          group-digits            = false ,
          input-signs             = ,
          input-symbols           = ()[]-+ ,
          input-open-uncertainty  = ,
          input-close-uncertainty = ,
          table-align-text-post   = false 
        }


\def\xxx#1{%
  \bgroup\uccode`\~\expandafter`\string#1%
  \uppercase{\egroup\edef~{\noexpand\text\string#1}}%
  \mathcode\expandafter`\string#1"8000 }
\def\textsymbols{\xxx[\xxx]\xxx(\xxx)}



\begin{document}

{\textsymbols
\begin{tabular*}{\textwidth}{
    l @{\extracolsep\fill} *{2}{S[table-format=4.4]} @{}}
\toprule
\multicolumn{1}{@{}l}{\emph{Age}}  \\[0.5ex]
18--24 &   [-1360.228]\sym{*}  &  -1371.941\sym{*}  \\
       &       (6.915)         &    (-7.953)        \\
25--34 &     -219.216          &   -240.271         \\
       &     (514.894)         &   (515.348)        \\
35--44 &     -310.715          &   -311.438         \\
       &     (485.780)         &   (486.013)        \\
55$+$  &       -5.135          &     [2.656]        \\
       &      (53.267)         &   (533.875)        \\
\bottomrule
\end{tabular*}}
\end{document}

If you are using amsmath, you need to make a slight correction after loading the package

\usepackage{amsmath}

\makeatletter
\edef\originalbmathcode{%
    \noexpand\mathchardef\noexpand\@tempa\the\mathcode`\(\relax}
\def\resetMathstrut@{%
  \setbox\z@\hbox{%
    \originalbmathcode
    \def\@tempb##1"##2##3{\the\textfont"##3\char"}%
    \expandafter\@tempb\meaning\@tempa \relax
  }%
  \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@
}
\makeatother

This still leaves - signs in math mode as noted in comments, that could be changed by adding - to the list of text symbols:

\def\yyy{%
  \bgroup\uccode`\~\expandafter`\string-%
  \uppercase{\egroup\edef~{\noexpand\text{\char"2212\relax}}}%
  \mathcode\expandafter`\string-"8000 }
\def\textsymbols{\xxx[\xxx]\xxx(\xxx)\yyy}

That is using (xetex) unicode slot for a - (−) sign however with the fonts as in the MWE the signs all disappear and the log says

Missing character: There is no − in font pplr9o!
Missing character: There is no − in font pplr9o!
Missing character: There is no − in font pplr9o!
Missing character: There is no − in font pplr9o!

however if you have a font that does have this character or a LaTeX command that produces something in that font, you could adapt \yyy to match.

David Carlisle
  • 757,742
  • Your solution works very well in the MWE, but it does not work at all when amsmath is loaded ("Bad mathchar (32768)"). Sorry, I should have mentioned amsmath in the MWE, but I was not aware that this might cause problems. Is there a way to make your example working? – Jörg Mar 02 '12 at 10:57
  • I should also mention that I have switched to XeTeX as it allows more flexibility with fonts. That does not change anything regarding the problem with amsmath, but maybe it is easier to find a solution with XeTeX. Ultimately, the problem is a typographical one: with your solution the minus sign and the asterisk are still set in Euler (something I can live with), but they should be set in the text font. – Jörg Mar 02 '12 at 11:02
  • will look in a bit.... – David Carlisle Mar 02 '12 at 11:02
  • On the minus sign, yes I wondered about that, it would be easy to add - to the list of characters in \textsymbols but it depends if your text font has a minus sign, you wouldn't want a hyphen. I suppose if you are using xetex than making it use U+2212 (unicode MINUS SIGN) directly would probably work. – David Carlisle Mar 02 '12 at 11:05
  • ams fix added to answer above – David Carlisle Mar 02 '12 at 11:30
  • possible approaches for - signs added to answer – David Carlisle Mar 02 '12 at 12:07
  • Excellent, both changes (for amsmath and minus sign) work perfectly with XeTeX and Adobe Garamond Pro! Thank you. – Jörg Mar 02 '12 at 12:21
  • I have realised that I have a problem with the asterisks. Because they are included by \sym{*} siunitx does not recognise them as symbol, even when I add * to the input-symbols list. The results are enormous amounts of overfull hboxes. Is there are way to include \sym to input-symbols? (I can create a follow up question with a new MWE if that is required). – Jörg Mar 09 '12 at 14:55
  • I suspect this is a siunitx question, I get a few overfull boxes when I run the MWE, but I get missing font errors as well, and I don't know siuntx or xetex;-) If you make a MWE just for this and say what looks wrong (either in the output or in the log) it might be easier – David Carlisle Mar 09 '12 at 15:21
  • Follow up question added here http://tex.stackexchange.com/questions/47418/siunitx-specifying-custom-command-as-input-symbol. The problem is not XeTeX specific. – Jörg Mar 09 '12 at 15:47
  • FYI: The amsmath fix given in this answer solves another problem I just had. When using the package together with the elsarticle documentclass, I would get the exact same "Bad mathchar" error (even though Elsevier claimed that their class would work fine with amsmath). So thanks! – mhelvens Dec 29 '12 at 17:24