6

How do I get \$ values centered properly in this table?

enter image description here

This should be straightforward, but a frustrating search on this site and in siunitx documentation didn't help me. Of course I can always put the units in the header row, as in the first column, but I'm curious.

MWE:

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{cS[table-format=3.2]S[table-format=2.0]S[table-format=4.2]}
\toprule
Plan & {Phone cost (\$)} & {Monthly charge} & {Two year cost} \\
\midrule
Cricket Wireless & 499.99 & \$55 & \$1,819.99 \\
Virgin Mobile &  649 & \$30 & \$1,369 \\
\bottomrule
\end{tabular}

\end{document}
2
  • Why don't you put ($) in the header of all columns?
    – egreg
    May 3, 2015 at 15:13
  • @egreg I could and I probably will but I'm curious. May 3, 2015 at 15:15

1 Answer 1

6

The best thing is to add ($) to all headers: repeating $ in several cells is boring and dull.

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\sisetup{
  group-separator={,},
  group-four-digits,
}

\begin{document}

\begin{tabular}{
  l
  S[table-format=3.2]
  S[table-format=2.0]
  S[table-format=4.2]
}
\toprule
Plan & {Phone cost} & {Monthly charge} & {Two year cost} \\
& {(\$)} & {(\$)} & {(\$)} \\
\midrule
Cricket Wireless & 499.99 & 55 & 1819.99 \\
Virgin Mobile &  649 & 30 & 1369 \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

Unrecommended way:

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\sisetup{
  group-separator={,},
  group-four-digits,
}

\begin{document}

\begin{tabular}{
  l
  S[table-format=3.2]
  S[table-format=2.0,table-space-text-pre={\$}]
  S[table-format=4.2,table-space-text-pre={\$}]
}
\toprule
Plan & {Phone cost (\$)} & {Monthly charge} & {Two year cost} \\
\midrule
Cricket Wireless & 499.99 & {\$}55 & {\$}1819.99 \\
Virgin Mobile &  649 & {\$}30 & {\$}1369 \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

1
  • I appreciate both answers and will go with no boring and dull (and left justify the first column). May 3, 2015 at 15:27

You must log in to answer this question.

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