2

I would like to have help to fix a small formatting issue on the last row of the table below.

As you can notice, the values on this row are on a much different scale of the other ones on the table, so I think using the same formatting style (aligning the rows at the decimal marker) for them would not be ideal.

I was wondering if there a way in which I could have only the last row to have the values centered, with . as the thousands separator, and , as the decimal marker -- while leaving the rest as it is formatted right now.

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage[utf8]{inputenc}
\usepackage[skip=0.333\baselineskip]{caption} 
\usepackage{newtxtext,newtxmath} 
\usepackage[vmargin=3cm, hmargin=2.5cm]{geometry}
\usepackage[group-separator={.},
            group-four-digits,
            output-decimal-marker={,}]{siunitx}
\newcommand\mc{\multicolumn{1}{c}}

\begin{document}
\begin{table}[ht]
\setlength\extrarowheight{2pt}
\caption{Estatísticas Descritivas - Características pessoais e  dos candidatos e tamanho das eleições no município  -- 2016} 
\centering
\begin{tabular}{lSSS}
  \toprule
  & \mc{Controle} & \mc{Tratado} & \mc{Total} \\ 
  \midrule
  Sexo & \\
  \hspace{4mm} Mulheres (\%)  & 12.4 & 12.1 & 12.4 \\
  \hspace{4mm} Homens (\%) & 87.6 & 87.9 & 87.6 \\
  \midrule
Cor &  \\
\hspace{4mm} Brancos (\%) & 56.1 & 57.2 & 56.3 \\ 
\hspace{4mm}  Amarelos ou Indígenas (\%) & 0.7 & 0.8 & 0.7 \\ 
 \hspace{4mm} Pretos ou Pardos (\%) & 43.2 & 42.0 & 43.0 \\ 
  \midrule
  Escolaridade &  \\
 \hspace{4mm} Até Ensino Fundamental incompleto (\%) & 18.5 & 10.3 & 17.0 \\ 
 \hspace{4mm} Até Ensino Médio incompleto (\%) & 18.1 & 15.1 & 17.5 \\ 
 \hspace{4mm} Até Ensino Superior incompleto (\%) & 40.2 & 39.8 & 40.1 \\ 
 \hspace{4mm} Ensino Superior completo (\%) & 23.2 & 34.8 & 25.4 \\ 
 \midrule
 Média do total de votos nominais no município & {21516.4} & {103050.7} & {37096.0} \\
   \bottomrule
\end{tabular}
\end{table}
\end{document}

1 Answer 1

2

Just use \num (a macro provided by the siunitx package) to format the numbers in the final row.

enter image description here

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage[utf8]{inputenc}
\usepackage[skip=0.333\baselineskip]{caption} 
\usepackage{newtxtext,newtxmath} 
\usepackage[vmargin=3cm, hmargin=2.5cm]{geometry}
\usepackage[group-separator={.},
            group-four-digits,
            output-decimal-marker={,}]{siunitx}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}

\begin{document}
\begin{table}[ht]
\setlength\extrarowheight{2pt}
\caption{Estatísticas Descritivas -- Características pessoais e  dos candidatos e tamanho das eleições no município -- 2016} 
\centering
\begin{tabular}{@{}lSSS@{}}
\toprule
   & {Controle} & {Tratado} & {Total} \\ 
\midrule
Sexo & \\
 \hspace{4mm} Mulheres (\%)  & 12.4 & 12.1 & 12.4 \\
 \hspace{4mm} Homens (\%) & 87.6 & 87.9 & 87.6 \\
 \midrule
Cor &  \\
 \hspace{4mm} Brancos (\%) & 56.1 & 57.2 & 56.3 \\ 
 \hspace{4mm}  Amarelos ou Indígenas (\%) & 0.7 & 0.8 & 0.7 \\ 
 \hspace{4mm} Pretos ou Pardos (\%) & 43.2 & 42.0 & 43.0 \\ 
 \midrule
Escolaridade &  \\
 \hspace{4mm} Até Ensino Fundamental incompleto (\%) & 18.5 & 10.3 & 17.0 \\ 
 \hspace{4mm} Até Ensino Médio incompleto (\%) & 18.1 & 15.1 & 17.5 \\ 
 \hspace{4mm} Até Ensino Superior incompleto (\%) & 40.2 & 39.8 & 40.1 \\ 
 \hspace{4mm} Ensino Superior completo (\%) & 23.2 & 34.8 & 25.4 \\ 
 \midrule
Média do total de votos nominais no município & 
     \num{21516.4} & \num{103050.7} & \num{37096.0} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
1
  • Incidentally, you may also want to issue the instruction \sisetup{table-format=2.1} immediately before \begin{tabular}{...}, in order to achieve better centering of the contents of columns 2, 3, and 4.
    – Mico
    Commented Aug 9, 2017 at 7:38

You must log in to answer this question.

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