There are two problems: the first is that after
\def\sa{10}
\def\sb{20}
the text \sa and \sb
will render as
10and 20
because TeX ignores spaces after control words.
Second problem. A control sequence can consist either of
- only one non alphabetic character (control symbols); or
- a string of one or more alphabetic characters, that is
[A-Za-z]
(control words)
Spaces are not ignored after control symbols.
However definitions with \def
allow for a fairly general syntax:
\def\cs<parameter text>{<replacement text>}
Here <parameter text>
can be whatever sequence of tokens, including the argument indicators #1
to #9
to denote arguments. But if there are tokens different from the argument indicators, they must appear after \cs
. So
\def\s_a{10}
is legal and defines a command \s
which requires the two tokens _a
to follow it. If you say after this
\def\s_b{20}
the command \s
is redefined and usage of \s_a
will trigger the error message
! Use of \s doesn't match its definition.
since \s
is not followed by _b
.
To solve both problems at once, use
\def\sa/{10}
\def\sb/{20}
and then \sa/ and \sb/
will render as
10 and 20
because the required /
after the commands' names stops the space ignoring feature.
I don't know how you might achieve your objective using the functionality of the dcolumn
package. Fortunately, it's fairly straightforward to do if you're willing to use the siunitx
package and its S
column type.
In the example below, I've taken your code and made a few changes that instruct siunitx
how to deal with symbols such as parentheses and brackets. Basically, the code tells siunitx
not to do anything "special" with these symbols. Note that I've moved most instructions related to the appearance of material in S
columns to the preamble. The only instruction provided as an option to the two S
columns is table-format=4.4
, as this is likely something that will change from table to table. Doing this is, of course, mainly a stylistic or taste issue.
\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage[osf]{mathpazo}
% 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}
Best Answer
Working from Boris' answer:
However, for your particular number, siunitx versions lower than 2.4n return a "number too big" error unless you round the number off (as you had originally indicated, but I forgot about). That prompted me to write the following MATLAB function that will print the LaTeX code for your numbers to whatever precision you want:
Examples:
But again, any recent version of siunitx and Boris' answer will work fine for rounded numbers, and siunitx 2.4n will work fine even without rounding.