
私は LaTex の初心者なので、以下の表の書式設定について助けていただきたいです。
\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{times}
\usepackage{dcolumn}
\usepackage[vmargin=3cm, hmargin=2.5cm]{geometry}
\usepackage[group-separator={.}]{siunitx}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\usepackage[group-separator={,}]{siunitx}
\begin{document}
\begin{table}[ht]
\centering\setlength\extrarowheight{2pt}
\caption{Estat\'{i}sticas - Contribui\c{c}\~{o}es}
\begin{tabular}{@{\extracolsep{4pt}}ll*{6}{d{5.2}}}
\toprule
{} & {} & \multicolumn{3}{c}{Mediana} & \multicolumn{3}{c}{Desvio Padr\~{a}o}\\
\cmidrule(lr){3-5}
\cmidrule(lr){6-8}
Ano & Vari\'{a}vel & {Controle} & {Tratado} & {Total} & {Controle} & {Tratado} & {Total} \\
\midrule
2012 & Total de receitas & 3413.90 & 8645.19 & 3967.80 & 18077.13 & 94897.57 & 45339.62 \\
& \hspace{4mm}Pessoas f\'{i}sicas & 300.00 & 2500.00 & 570.00 & 6201.29 & 20180.83 & 10763.53 \\
& \hspace{4mm} Empresas & 0.00 & 1000.00 & 0.00 & 0.00 & 27854.24 & 12448.01 \\
& \hspace{4mm} Partidos & 0.00 & 0.00 & 0.00 & 7193.99 & 54075.33 & 24547.63 \\
& \hspace{4mm} Recursos pr\'{o}prios & 1550.00 & 1850.00 & 1598.00 & 5694.75 & 12012.86 & 7382.93 \\
& \hspace{4mm} Outros recursos & 91.88 & 230.00 & 103.13 & 8456.98 & 21893.65 & 12259.07 \\ \\
& Pessoas f\'{i}sicas (\%) & 12.10 & 30.20 & 16.90 & 31.06 & 28.57 & 30.73 \\
& Empresas (\%) & 0.00 & 14.20 & 0.00 & 0.00 & 24.69 & 14.21 \\
& Partidos (\%) & 0.00 & 0.00 & 0.00 & 9.78 & 9.50 & 9.73 \\
& Recursos pr\'{o}prios (\%) & 57.90 & 22.70 & 49.90 & 36.33 & 28.93 & 36.31 \\
& Outros recursos (\%) & 2.90 & 2.50 & 2.80 & 27.84 & 16.73 & 26.23 \\
\midrule
2016 & Total de receitas & 3600.00 & 7106.27 & 4009.00 & 11740.78 & 52605.28 & 25877.30 \\
& \hspace{4mm} Pessoas f\'{i}sicas & 800.00 & 2344.70 & 1000.00 & 6136.54 & 27232.84 & 13392.53 \\
& \hspace{4mm} Empresas & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
& \hspace{4mm} Partidos & 0.00 & 0.00 & 0.00 & 4343.52 & 28402.71 & 13027.55 \\
& \hspace{4mm} Recursos pr\'{o}prios & 1695.00 & 3000.00 & 1857.72 & 6576.61 & 20169.18 & 10796.12 \\
& \hspace{4mm} Outros recursos & 37.50 & 88.00 & 44.80 & 1544.50 & 6476.34 & 3160.15 \\ \\
& Pessoas f\'{i}sicas (\%) & 26.70 & 37.30 & 28.90 & 31.18 & 31.46 & 31.35 \\
& Empresas (\%) & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
& Partidos (\%) & 0.00 & 0.00 & 0.00 & 13.50 & 13.18 & 13.44 \\
& Recursos pr\'{o}prios (\%) & 56.00 & 48.80 & 54.60 & 33.71 & 32.59 & 33.54 \\
& Outros recursos (\%) & 0.70 & 0.80 & 0.80 & 20.21 & 16.07 & 19.51 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
理由はわかりませんが、dcolumn
パッケージを使用した後、一部の列名が斜体で表示され、それぞれの値に揃えられませんでした。これはなぜですか。また、どうすれば修正できますか。
3桁ごとの区切りと小数点にカンマを付けて表に数字を表示するにはどうすればよいですか? たとえば、次のようになります1.000.000,00
。
もう 1 つ: ドキュメントに必要な余白を使用しても、表が PDF ページにうまく収まりません。中央に配置して収まるようにするにはどうすればよいでしょうか。最終的なドキュメントには他にも多くの表が含まれる予定ですが、floating
オプションを使用することの長所と短所がよくわかりません。
本当に助かります!その他のコメントや提案も歓迎します!
ありがとう!
答え1
表形式の資料をテキスト ブロック内に収めるには、(a) ディレクティブを削除し@{\extracolsep{4pt}}
、(b)環境tabular*
の代わりに環境を使用し、(c) 環境を開始する前にtabular
命令を発行し、定義のヘッダー内でディレクティブを使用する必要があります。こうすることで、LaTeX が列間の空白の最適な値を計算できるようになります。\setlength\tabcolsep{0pt}
tabular*
@{\extracolsep{\fill}}
tabular*
これらの提案を実践するには、次の設定を使用することをお勧めします。
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
ll *{3}{S[table-format=4.2]} *{3}{S[table-format=5.2]} }
数字の書式設定に関して:dcolumn
と の両方をロードしないでくださいsiunitx
。LaTeX で 3000 ごとの区切り記号を自動的に挿入したいので、siunitx
パッケージとそのS
列タイプに集中することをお勧めします。
完全な MWE - パッケージは非推奨であることに注意してください。パッケージとパッケージtimes
をロードすることをお勧めします。newtxtext
newtxmath
\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}
\begin{document}
\begin{table}[ht]
\setlength\tabcolsep{0pt} % <-- new
\setlength\extrarowheight{2pt}
\caption{Estat\'{i}sticas -- Contribui\c{c}\~{o}es}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} % <-- new
ll *{3}{S[table-format=4.2]} *{3}{S[table-format=5.2]} } % <-- new
\toprule
& & \multicolumn{3}{c}{Mediana} & \multicolumn{3}{c}{Desvio Padr\~{a}o}\\
\cmidrule{3-5} \cmidrule{6-8}
Ano & Vari\'{a}vel & {Controle} & {Tratado} & {Total} & {Controle} & {Tratado} & {Total} \\
\midrule
2012 & Total de receitas & 3413.90 & 8645.19 & 3967.80 & 18077.13 & 94897.57 & 45339.62 \\
& \hspace{4mm}Pessoas f\'{i}sicas & 300.00 & 2500.00 & 570.00 & 6201.29 & 20180.83 & 10763.53 \\
& \hspace{4mm}Empresas & 0.00 & 1000.00 & 0.00 & 0.00 & 27854.24 & 12448.01 \\
& \hspace{4mm}Partidos & 0.00 & 0.00 & 0.00 & 7193.99 & 54075.33 & 24547.63 \\
& \hspace{4mm}Recursos pr\'{o}prios & 1550.00 & 1850.00 & 1598.00 & 5694.75 & 12012.86 & 7382.93 \\
& \hspace{4mm}Outros recursos & 91.88 & 230.00 & 103.13 & 8456.98 & 21893.65 & 12259.07 \\
\addlinespace
& Pessoas f\'{i}sicas (\%) & 12.10 & 30.20 & 16.90 & 31.06 & 28.57 & 30.73 \\
& Empresas (\%) & 0.00 & 14.20 & 0.00 & 0.00 & 24.69 & 14.21 \\
& Partidos (\%) & 0.00 & 0.00 & 0.00 & 9.78 & 9.50 & 9.73 \\
& Recursos pr\'{o}prios (\%) & 57.90 & 22.70 & 49.90 & 36.33 & 28.93 & 36.31 \\
& Outros recursos (\%) & 2.90 & 2.50 & 2.80 & 27.84 & 16.73 & 26.23 \\
\midrule
2016 & Total de receitas & 3600.00 & 7106.27 & 4009.00 & 11740.78 & 52605.28 & 25877.30 \\
& \hspace{4mm}Pessoas f\'{i}sicas & 800.00 & 2344.70 & 1000.00 & 6136.54 & 27232.84 & 13392.53 \\
& \hspace{4mm}Empresas & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
& \hspace{4mm}Partidos & 0.00 & 0.00 & 0.00 & 4343.52 & 28402.71 & 13027.55 \\
& \hspace{4mm}Recursos pr\'{o}prios & 1695.00 & 3000.00 & 1857.72 & 6576.61 & 20169.18 & 10796.12 \\
& \hspace{4mm}Outros recursos & 37.50 & 88.00 & 44.80 & 1544.50 & 6476.34 & 3160.15 \\
\addlinespace
& Pessoas f\'{i}sicas (\%) & 26.70 & 37.30 & 28.90 & 31.18 & 31.46 & 31.35 \\
& Empresas (\%) & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
& Partidos (\%) & 0.00 & 0.00 & 0.00 & 13.50 & 13.18 & 13.44 \\
& Recursos pr\'{o}prios (\%) & 56.00 & 48.80 & 54.60 & 33.71 & 32.59 & 33.54 \\
& Outros recursos (\%) & 0.70 & 0.80 & 0.80 & 20.21 & 16.07 & 19.51 \\
\bottomrule
\end{tabular*} % <-- new
\end{table}
\end{document}
答え2
詳しく説明しましょうアラン・マンコメント:
S
あなたが好きなものは、列タイプから簡単に達成できますsiunitx
\sisetup{...}
グループ化の最小数字を定義するsiunitx
1つをロードするだけで十分です
したがって、MWE の次の変更によって、希望どおりの結果が得られるかどうかを確認してください。
\documentclass[12pt]{article}
\usepackage[vmargin=3cm, hmargin=2.5cm]{geometry}
\usepackage{times}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{caption}
\begin{document}
\begin{table}[ht]
% \small
\centering
\setlength\extrarowheight{2pt}
\sisetup{table-format = 5.2,group-separator={.},
group-separator={.},
output-decimal-marker={,},
group-four-digits}
\caption{Estat\'{i}sticas - Contribui\c{c}\~{o}es}
\begin{tabular}{ll*{6}{S}}
\toprule
...
\bottomrule
\end{tabular}
\end{table}
\end{document}
注記:
を削除しても、テーブルがテキスト幅に収まらないほど広すぎますextracolsep
。