3

the solution to these problems are probably silly. Anyway, why are the columns 2012 and 2016 not having the text centered?

I have done exactly the same thing on other tables and it has worked.

Other minor issue: Why is the caption not being displayed?

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{teste tabela}
\author{arthurcbps }
\date{July 2017}

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


\begin{document}
\setlength\tabcolsep{0pt} % <-- new
\setlength\extrarowheight{2pt}
\caption{Distribui\c{c}\~{a}o dos partidos}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
   lrrrrrr}
   \toprule
    \multicolumn{3}{c}{2012} & \multicolumn{3}{c}{2016}\\
  \cmidrule{2-4} \cmidrule{5-7}
Partido & \M{Controle} & \M{Tratado} & \M{Total} & \M{Controle} & \M{Tratado} & \M{Total} \\ 
  \midrule
PMDB & 4436 (13.7\%) & 917 (12\%) & 5353 (13.4\%) & 4374 (13.6\%) & 933 (12.2\%) & 5307 (13.3\%) \\ 
  PSDB & 2968 (9.2\%) & 641 (8.4\%) & 3609 (9\%) & 3072 (9.5\%) & 671 (8.8\%) & 3743 (9.4\%) \\ 
  PSD & 2579 (8\%) & 557 (7.3\%) & 3136 (7.9\%) & 2650 (8.2\%) & 589 (7.7\%) & 3239 (8.1\%) \\ 
  PP & 2813 (8.7\%) & 503 (6.6\%) & 3316 (8.3\%) & 2678 (8.3\%) & 451 (5.9\%) & 3129 (7.8\%) \\ 
  PDT & 2095 (6.5\%) & 505 (6.6\%) & 2600 (6.5\%) & 2070 (6.4\%) & 473 (6.2\%) & 2543 (6.4\%) \\ 
  PSB & 2010 (6.2\%) & 478 (6.3\%) & 2488 (6.2\%) & 2033 (6.3\%) & 491 (6.4\%) & 2524 (6.3\%) \\ 
  PT & 2835 (8.8\%) & 799 (10.5\%) & 3634 (9.1\%) & 1923 (6\%) & 534 (7\%) & 2457 (6.2\%) \\ 
  DEM & 1880 (5.8\%) & 398 (5.2\%) & 2278 (5.7\%) & 1786 (5.5\%) & 374 (4.9\%) & 2160 (5.4\%) \\ 
  PTB & 2088 (6.5\%) & 456 (6\%) & 2544 (6.4\%) & 1736 (5.4\%) & 416 (5.5\%) & 2152 (5.4\%) \\ 
  PR & 1837 (5.7\%) & 426 (5.6\%) & 2263 (5.7\%) & 1692 (5.2\%) & 426 (5.6\%) & 2118 (5.3\%) \\ 
  PPS & 1070 (3.3\%) & 268 (3.5\%) & 1338 (3.4\%) & 899 (2.8\%) & 227 (3\%) & 1126 (2.8\%) \\ 
  PSC & 801 (2.5\%) & 247 (3.2\%) & 1048 (2.6\%) & 825 (2.6\%) & 208 (2.7\%) & 1033 (2.6\%) \\ 
  SD & \M{-} & \M{-} & \M{-} & 775 (2.4\%) & 241 (3.2\%) & 1016 (2.5\%) \\ 
  PV & 864 (2.7\%) & 240 (3.1\%) & 1104 (2.8\%) & 780 (2.4\%) & 189 (2.5\%) & 969 (2.4\%) \\ 
  PRB & 687 (2.1\%) & 198 (2.6\%) & 885 (2.2\%) & 726 (2.2\%) & 229 (3\%) & 955 (2.4\%) \\ 
  PROS & \M{-} & \M{-} & \M{-} & 596 (1.8\%) & 148 (1.9\%) & 744 (1.9\%) \\ 
  PC do B & 506 (1.6\%) & 173 (2.3\%) & 679 (1.7\%) & 512 (1.6\%) & 163 (2.1\%) & 675 (1.7\%) \\ 
  PSL & 434 (1.3\%) & 108 (1.4\%) & 542 (1.4\%) & 487 (1.5\%) & 113 (1.5\%) & 600 (1.5\%) \\ 
  PHS & 310 (1\%) & 85 (1.1\%) & 395 (1\%) & 389 (1.2\%) & 109 (1.4\%) & 498 (1.2\%) \\ 
  PTN & 236 (0.7\%) & 87 (1.1\%) & 323 (0.8\%) & 369 (1.1\%) & 109 (1.4\%) & 478 (1.2\%) \\ 
  PTC & 276 (0.9\%) & 93 (1.2\%) & 369 (0.9\%) & 258 (0.8\%) & 73 (1\%) & 331 (0.8\%) \\ 
  PMN & 349 (1.1\%) & 96 (1.3\%) & 445 (1.1\%) & 249 (0.8\%) & 62 (0.8\%) & 311 (0.8\%) \\ 
  PT do B & 282 (0.9\%) & 90 (1.2\%) & 372 (0.9\%) & 231 (0.7\%) & 62 (0.8\%) & 293 (0.7\%) \\ 
  PSDC & 233 (0.7\%) & 78 (1\%) & 311 (0.8\%) & 191 (0.6\%) & 62 (0.8\%) & 253 (0.6\%) \\ 
  PRTB & 226 (0.7\%) & 69 (0.9\%) & 295 (0.7\%) & 184 (0.6\%) & 51 (0.7\%) & 235 (0.6\%) \\ 
  PEN & \M{-} & \M{-} & \M{-} & 169 (0.5\%) & 32 (0.4\%) & 201 (0.5\%) \\ 
  PMB & \M{-} & \M{-} & \M{-} & 135 (0.4\%) & 47 (0.6\%) & 182 (0.5\%) \\ 
  REDE & \M{-} & \M{-} & \M{-} & 115 (0.4\%) & 35 (0.5\%) & 150 (0.4\%) \\ 
  PPL & 100 (0.3\%) & 16 (0.2\%) & 116 (0.3\%) & 40 (0.1\%) & 10 (0.1\%) & 50 (0.1\%) \\ 
  PSOL & 21 (0.1\%) & 13 (0.2\%) & 34 (0.1\%) & 19 (0.1\%) & 8 (0.1\%) & 27 (0.1\%) \\ 
  PRP & 329 (1\%) & 82 (1.1\%) & 411 (1\%) & 307 (1\%) & 87 (1.1\%) & 394 (1\%) \\ 
  PCB & 5 (0\%) & \M{-} & 5 (0\%) & \M{-} & \M{-} & \M{-} \\ 
  PSTU & 1 (0\%) & \M{-} & 1 (0\%) & 1 (0\%) & \M{-} & 1 (0\%) \\ 

 \bottomrule
\end{tabular*} % <-- new

\end{document}
3

The problem was a missing &.

You need a table environment, if you want a caption.

I suggest a different setting for the table, with separate columns for the votes and the percentage:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{booktabs}
\usepackage[skip=0.333\baselineskip]{caption} % <-- new
\usepackage{newtxtext,newtxmath} % <-- new
\usepackage[vmargin=3cm, hmargin=2.5cm]{geometry}
\usepackage[group-separator={.},
%            group-four-digits,
            output-decimal-marker={,}]{siunitx}
\newcommand{\M}[1]{\multicolumn{2}{c}{#1}}
\newcommand{\lparen}{(}
\newcommand{\rparen}{)}

\begin{document}

\begin{table}[htp]

\setlength\tabcolsep{0pt} % <-- new
\setlength\extrarowheight{2pt}
\caption{Distribui\c{c}\~{a}o dos partidos}
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  *{5}{
    S[table-format=4.0]
    @{\extracolsep{0pt}\hspace{3pt}}
    >{\lparen}
    S[table-format=2.1,
      table-space-text-pre=(,
      table-space-text-post=\%),
      table-align-text-pre=false,
      table-auto-round,
      round-integer-to-decimal,
    ]
    <{\%\rparen}
    @{\extracolsep{\fill}}
  }
    S[table-format=4.0]
    @{\extracolsep{0pt}\hspace{3pt}}
    >{\lparen}
    S[table-format=2.1,
      table-space-text-pre=(,
      table-space-text-post=\%),
      table-align-text-pre=false,
      table-auto-round=true,
      round-integer-to-decimal,
    ]
    <{\%\rparen}
    r@{}
}
\toprule
& \multicolumn{6}{c}{2012} & \multicolumn{6}{c}{2016}& \\
  \cmidrule{2-7} \cmidrule{8-13}
Partido & \M{Controle} & \M{Tratado} & \M{Total} & \M{Controle} & \M{Tratado} & \M{Total} & \\ 
  \midrule
PMDB & 4436 & 13.7 & 917 & 12 & 5353 & 13.4 & 4374 & 13.6 & 933 & 12.2 & 5307 & 13.3 & \\ 
PSDB & 2968 & 9.2 & 641 & 8.4 & 3609 & 9 & 3072 & 9.5 & 671 & 8.8 & 3743 & 9.4 & \\ 
PSD & 2579 & 8 & 557 & 7.3 & 3136 & 7.9 & 2650 & 8.2 & 589 & 7.7 & 3239 & 8.1 & \\ 
PP & 2813 & 8.7 & 503 & 6.6 & 3316 & 8.3 & 2678 & 8.3 & 451 & 5.9 & 3129 & 7.8 & \\ 
PDT & 2095 & 6.5 & 505 & 6.6 & 2600 & 6.5 & 2070 & 6.4 & 473 & 6.2 & 2543 & 6.4 & \\ 
PSB & 2010 & 6.2 & 478 & 6.3 & 2488 & 6.2 & 2033 & 6.3 & 491 & 6.4 & 2524 & 6.3 & \\ 
PT & 2835 & 8.8 & 799 & 10.5 & 3634 & 9.1 & 1923 & 6 & 534 & 7 & 2457 & 6.2 & \\ 
DEM & 1880 & 5.8 & 398 & 5.2 & 2278 & 5.7 & 1786 & 5.5 & 374 & 4.9 & 2160 & 5.4 & \\ 
PTB & 2088 & 6.5 & 456 & 6 & 2544 & 6.4 & 1736 & 5.4 & 416 & 5.5 & 2152 & 5.4 & \\ 
PR & 1837 & 5.7 & 426 & 5.6 & 2263 & 5.7 & 1692 & 5.2 & 426 & 5.6 & 2118 & 5.3 & \\ 
PPS & 1070 & 3.3 & 268 & 3.5 & 1338 & 3.4 & 899 & 2.8 & 227 & 3 & 1126 & 2.8 & \\ 
PSC & 801 & 2.5 & 247 & 3.2 & 1048 & 2.6 & 825 & 2.6 & 208 & 2.7 & 1033 & 2.6 & \\ 
SD & \M{---} & \M{---} & \M{---} & 775 & 2.4 & 241 & 3.2 & 1016 & 2.5 & \\ 
PV & 864 & 2.7 & 240 & 3.1 & 1104 & 2.8 & 780 & 2.4 & 189 & 2.5 & 969 & 2.4 & \\ 
PRB & 687 & 2.1 & 198 & 2.6 & 885 & 2.2 & 726 & 2.2 & 229 & 3 & 955 & 2.4 & \\ 
PROS & \M{---} & \M{---} & \M{---} & 596 & 1.8 & 148 & 1.9 & 744 & 1.9 & \\ 
PC do B & 506 & 1.6 & 173 & 2.3 & 679 & 1.7 & 512 & 1.6 & 163 & 2.1 & 675 & 1.7 & \\ 
PSL & 434 & 1.3 & 108 & 1.4 & 542 & 1.4 & 487 & 1.5 & 113 & 1.5 & 600 & 1.5 & \\ 
PHS & 310 & 1 & 85 & 1.1 & 395 & 1 & 389 & 1.2 & 109 & 1.4 & 498 & 1.2 & \\ 
PTN & 236 & 0.7 & 87 & 1.1 & 323 & 0.8 & 369 & 1.1 & 109 & 1.4 & 478 & 1.2 & \\ 
PTC & 276 & 0.9 & 93 & 1.2 & 369 & 0.9 & 258 & 0.8 & 73 & 1 & 331 & 0.8 & \\ 
PMN & 349 & 1.1 & 96 & 1.3 & 445 & 1.1 & 249 & 0.8 & 62 & 0.8 & 311 & 0.8 & \\ 
PT do B & 282 & 0.9 & 90 & 1.2 & 372 & 0.9 & 231 & 0.7 & 62 & 0.8 & 293 & 0.7 & \\ 
PSDC & 233 & 0.7 & 78 & 1 & 311 & 0.8 & 191 & 0.6 & 62 & 0.8 & 253 & 0.6 & \\ 
PRTB & 226 & 0.7 & 69 & 0.9 & 295 & 0.7 & 184 & 0.6 & 51 & 0.7 & 235 & 0.6 & \\ 
PEN & \M{---} & \M{---} & \M{---} & 169 & 0.5 & 32 & 0.4 & 201 & 0.5 & \\ 
PMB & \M{---} & \M{---} & \M{---} & 135 & 0.4 & 47 & 0.6 & 182 & 0.5 & \\ 
REDE & \M{---} & \M{---} & \M{---} & 115 & 0.4 & 35 & 0.5 & 150 & 0.4 & \\ 
PPL & 100 & 0.3 & 16 & 0.2 & 116 & 0.3 & 40 & 0.1 & 10 & 0.1 & 50 & 0.1 & \\ 
PSOL & 21 & 0.1 & 13 & 0.2 & 34 & 0.1 & 19 & 0.1 & 8 & 0.1 & 27 & 0.1 & \\ 
PRP & 329 & 1 & 82 & 1.1 & 411 & 1 & 307 & 1 & 87 & 1.1 & 394 & 1 & \\ 
PCB & 5 & 0 & \M{---} & 5 & 0 & \M{---} & \M{---} & \M{---} & \\ 
PSTU & 1 & 0 & \M{---} & 1 & 0 & 1 & 0 & \M{---} & 1 & 0 & \\ 

 \bottomrule
\end{tabular*} % <-- new

\end{table}

\end{document}

I wouldn't add a separator for four digit figures.

enter image description here

  • This table will be placed on a document with other tables. How can I leave the separator on other tables but not on this one? – Arthur Carvalho Brito Jul 18 '17 at 1:30
  • Sorry about so many questions... but supposing that I had a table with only the 2012 part of the original one, how should I change the code so that I had the same format as the one you have just posted? What did you do to remove the parentheses? – Arthur Carvalho Brito Jul 18 '17 at 6:03
  • 1
    @ArthurCarvalhoBrito You can do \sisetup{group-four-digits=false} in the table environment, if you have the option turned on globally. For a table with a single year, use the same preamble with *{2} instead of *{5}. – egreg Jul 18 '17 at 7:17
4

Headers 2012 and 2016 are not centered because of a missing first tabular mark &. Caption is not being displayed because it should be used with a float environment, for tabulars it is table.

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

\begin{document}

\begin{table}             % <-- missing float environment
\setlength\tabcolsep{0pt} % <-- new
\setlength\extrarowheight{2pt}
\caption{Distribui\c{c}\~{a}o dos partidos}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
   lrrrrrr}
   \toprule
   & \multicolumn{3}{c}{2012} & \multicolumn{3}{c}{2016}\\ % <-- first & missing
  \cmidrule{2-4} \cmidrule{5-7}
Partido & \M{Controle} & \M{Tratado} & \M{Total} & \M{Controle} & \M{Tratado} & \M{Total} \\ 
  \midrule
PMDB & 4436 (13.7\%) & 917 (12\%) & 5353 (13.4\%) & 4374 (13.6\%) & 933 (12.2\%) & 5307 (13.3\%) \\ 
  PSDB & 2968 (9.2\%) & 641 (8.4\%) & 3609 (9\%) & 3072 (9.5\%) & 671 (8.8\%) & 3743 (9.4\%) \\ 
  PSD & 2579 (8\%) & 557 (7.3\%) & 3136 (7.9\%) & 2650 (8.2\%) & 589 (7.7\%) & 3239 (8.1\%) \\ 
  PP & 2813 (8.7\%) & 503 (6.6\%) & 3316 (8.3\%) & 2678 (8.3\%) & 451 (5.9\%) & 3129 (7.8\%) \\ 
  PDT & 2095 (6.5\%) & 505 (6.6\%) & 2600 (6.5\%) & 2070 (6.4\%) & 473 (6.2\%) & 2543 (6.4\%) \\ 
  PSB & 2010 (6.2\%) & 478 (6.3\%) & 2488 (6.2\%) & 2033 (6.3\%) & 491 (6.4\%) & 2524 (6.3\%) \\ 
  PT & 2835 (8.8\%) & 799 (10.5\%) & 3634 (9.1\%) & 1923 (6\%) & 534 (7\%) & 2457 (6.2\%) \\ 
  DEM & 1880 (5.8\%) & 398 (5.2\%) & 2278 (5.7\%) & 1786 (5.5\%) & 374 (4.9\%) & 2160 (5.4\%) \\ 
  PTB & 2088 (6.5\%) & 456 (6\%) & 2544 (6.4\%) & 1736 (5.4\%) & 416 (5.5\%) & 2152 (5.4\%) \\ 
  PR & 1837 (5.7\%) & 426 (5.6\%) & 2263 (5.7\%) & 1692 (5.2\%) & 426 (5.6\%) & 2118 (5.3\%) \\ 
  PPS & 1070 (3.3\%) & 268 (3.5\%) & 1338 (3.4\%) & 899 (2.8\%) & 227 (3\%) & 1126 (2.8\%) \\ 
  PSC & 801 (2.5\%) & 247 (3.2\%) & 1048 (2.6\%) & 825 (2.6\%) & 208 (2.7\%) & 1033 (2.6\%) \\ 
  SD & \M{-} & \M{-} & \M{-} & 775 (2.4\%) & 241 (3.2\%) & 1016 (2.5\%) \\ 
  PV & 864 (2.7\%) & 240 (3.1\%) & 1104 (2.8\%) & 780 (2.4\%) & 189 (2.5\%) & 969 (2.4\%) \\ 
  PRB & 687 (2.1\%) & 198 (2.6\%) & 885 (2.2\%) & 726 (2.2\%) & 229 (3\%) & 955 (2.4\%) \\ 
  PROS & \M{-} & \M{-} & \M{-} & 596 (1.8\%) & 148 (1.9\%) & 744 (1.9\%) \\ 
  PC do B & 506 (1.6\%) & 173 (2.3\%) & 679 (1.7\%) & 512 (1.6\%) & 163 (2.1\%) & 675 (1.7\%) \\ 
  PSL & 434 (1.3\%) & 108 (1.4\%) & 542 (1.4\%) & 487 (1.5\%) & 113 (1.5\%) & 600 (1.5\%) \\ 
  PHS & 310 (1\%) & 85 (1.1\%) & 395 (1\%) & 389 (1.2\%) & 109 (1.4\%) & 498 (1.2\%) \\ 
  PTN & 236 (0.7\%) & 87 (1.1\%) & 323 (0.8\%) & 369 (1.1\%) & 109 (1.4\%) & 478 (1.2\%) \\ 
  PTC & 276 (0.9\%) & 93 (1.2\%) & 369 (0.9\%) & 258 (0.8\%) & 73 (1\%) & 331 (0.8\%) \\ 
  PMN & 349 (1.1\%) & 96 (1.3\%) & 445 (1.1\%) & 249 (0.8\%) & 62 (0.8\%) & 311 (0.8\%) \\ 
  PT do B & 282 (0.9\%) & 90 (1.2\%) & 372 (0.9\%) & 231 (0.7\%) & 62 (0.8\%) & 293 (0.7\%) \\ 
  PSDC & 233 (0.7\%) & 78 (1\%) & 311 (0.8\%) & 191 (0.6\%) & 62 (0.8\%) & 253 (0.6\%) \\ 
  PRTB & 226 (0.7\%) & 69 (0.9\%) & 295 (0.7\%) & 184 (0.6\%) & 51 (0.7\%) & 235 (0.6\%) \\ 
  PEN & \M{-} & \M{-} & \M{-} & 169 (0.5\%) & 32 (0.4\%) & 201 (0.5\%) \\ 
  PMB & \M{-} & \M{-} & \M{-} & 135 (0.4\%) & 47 (0.6\%) & 182 (0.5\%) \\ 
  REDE & \M{-} & \M{-} & \M{-} & 115 (0.4\%) & 35 (0.5\%) & 150 (0.4\%) \\ 
  PPL & 100 (0.3\%) & 16 (0.2\%) & 116 (0.3\%) & 40 (0.1\%) & 10 (0.1\%) & 50 (0.1\%) \\ 
  PSOL & 21 (0.1\%) & 13 (0.2\%) & 34 (0.1\%) & 19 (0.1\%) & 8 (0.1\%) & 27 (0.1\%) \\ 
  PRP & 329 (1\%) & 82 (1.1\%) & 411 (1\%) & 307 (1\%) & 87 (1.1\%) & 394 (1\%) \\ 
  PCB & 5 (0\%) & \M{-} & 5 (0\%) & \M{-} & \M{-} & \M{-} \\ 
  PSTU & 1 (0\%) & \M{-} & 1 (0\%) & 1 (0\%) & \M{-} & 1 (0\%) \\ 
 \bottomrule
\end{tabular*} % <-- new

\end{table}    % <-- 

\end{document}
  • Thank You! I thought I had to choose between using tabular or P table. So I guess I need to put both? – Arthur Carvalho Brito Jul 17 '17 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.