2

Because, in my usage, most of hyphens(-) used inside of the table environment represent the minus sign, I would like to substitute them with \ensuremath{-}.

Here's my try:

\documentclass[10pt]{article}
\usepackage{threeparttable,booktabs}
\NewCommandCopy{\oldhyphen}{-}

\begin{document}
        
\begin{table}[ht]
    \begin{threeparttable}[t]
        \catcode`-=\active\def-{\ensuremath{\oldhyphen}}
        \begin{tabular}{lcc} \toprule 
        & -1.1484   & $-4.4464$ \\
        & (0.075)   & (0.322) \\
        \bottomrule 
        \end{tabular}
    \end{threeparttable}
\end{table} 

How can I redefine the table environment to do this automatically?

2
  • 5
    A better solution would be to define custom column types to format your tables properly e.g. using siunitx. Just changing the -s won't result in correct spacing or alignment.
    – cfr
    Commented May 21 at 2:42
  • To further argue for special column types: Turning - active in tables will break things like \cline and many other commands that parse for a - symbol.
    – Skillmon
    Commented May 21 at 3:47

1 Answer 1

6

As @cfr said in her comment: try to use siunitx package. For starting point may serve this simple example:

\documentclass[10pt]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{input-symbols = {()} }
\begin{document}
        
\begin{table}[ht]
\begin{tabular}{l*{2}{S[table-format=-1.4]} }
    \toprule 
        & -1.1484   & -4.4464 \\
        & (0.075)   & (0.322) \\
    \bottomrule 
        \end{tabular}
\end{table} 
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .