使用多列后无法使文本居中

使用多列后无法使文本居中

这些问题的解决方案可能很愚蠢。无论如何,为什么列20122016文本不居中?

我在其他桌子上做了完全相同的事情并且成功了。

其他小问题:为什么不显示标题?

\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}

答案1

问题是缺少了&

table如果您想要一个标题,那么您就需要一个环境。

我建议对表格进行不同的设置,将投票数和百分比分为不同的列:

\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}

我不会为四位数字添加分隔符。

在此处输入图片描述

答案2

由于缺少第一个表格标记 ,标题2012和未居中。标题未显示,因为它应与浮动环境一起使用,但对于s 来说,它是。2016&tabulartable

\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}

相关内容