
저는 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
패키지를 사용한 후 일부 열 이름이 기울임꼴로 표시되고 해당 값에 맞춰 정렬되지 않았습니다. 그 이유는 무엇이며 어떻게 고칠 수 있습니까?
소수점에 천 단위 구분 기호와 쉼표를 사용하여 테이블에 숫자를 표시하려면 어떻게 해야 합니까? 예를 1.000.000,00
들면.
또 다른 점: 문서에 필요한 여백을 사용하면 표가 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에서 천 단위 구분 기호를 자동으로 삽입하도록 하려면 패키지 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
로드하는 것만 으로도 충분합니다 .
따라서 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
.