格式化表格

格式化表格

你能帮我格式化这两个表格吗?我快要提交论文了,但我发现格式化这两个表格时出现了一些问题。

这是我正在使用的序言

\documentclass[12pt,a4paper]{article}
\usepackage[dvips]{graphicx} 
\usepackage[portuges]{babel}
\usepackage[latin1]{inputenc}
\usepackage{verbatim}
\usepackage{natbib}
\usepackage{amssymb}
%\usepackage[none]{hyphenat}
\usepackage{subcaption} 
\usepackage{amsmath,amssymb,mathtools}
\usepackage{indentfirst}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{rotfloat}
\usepackage{lscape}
\usepackage{booktabs} 
\usepackage{array} 
\usepackage{siunitx,booktabs,caption}
\usepackage[nodisplayskipstretch]{setspace}
%\usepackage{setspace}

%\newcommand{\splitcell}[1]{\begin{tabular}{@{}c@{}}\strut#1\strut\end{tabular}}

\def\arraystretch{0.9}

\setstretch{1.5} 

\setlength{\oddsidemargin}{0in}  %left margin position, reference is one inch
\setlength{\textwidth}{6.5in}    %width of text=8.5-1in-1in for margin
\setlength{\topmargin}{-0.5in}    %reference is at 1.5in, -.5in gives a start of about 1in from top
\setlength{\textheight}{9in}     %length of text=11in-1in-1in (top and bot. marg.) 


\begin{document}

...

\end{document}

第一个是关于列之间的空间。这是代码

    \begin{sidewaystable}[tbp] \centering \small
\caption{Nível da população}\label{nivelpopulacao2}
\setlength{\tabcolsep}{0.5pt}
        \begin{tabular}{@{}ccccccccccccc@{}}
\toprule
& \multicolumn{3}{c}{\multirow{2}*{\parbox{3.5cm}{Pop. (milhões de pessoas) }}} &\multicolumn{2}{c}{\multirow{2}*{\parbox{3cm}{Tx. cresc. médio anual (\%)}}} & \multicolumn{3}{c}{\parbox{3.5cm}{Distrib. etária (\%)}} & \multicolumn{2}{c}{Pop. ativa (\%)} & \multirow{2}*{\parbox{3cm}{Tx. de Mortalidade (por 1000 pessoas)}}& \parbox{3cm}{Tx. de Natalidade (por 1000 pessoas)} \\ \cline{7-11}
& \multicolumn{3}{c}{} & \multicolumn{2}{c}{} & 0-14 & 15-64 & 65$+$ & Jovem & 
Idosa & & \\ \cline{2-13}
& 1990 & 2008 & 2015 & 1990-2008 & 2008-15 & 2008 & 2008 & 2008 & 2008 & 2008
& 2008 & 2008 \\  \midrule
\multicolumn{1}{l}{\textbf{Mundo}} & 5.278,9 & 6.697,3 & 7.241,2 & 1,3 & 1,1
& 27 & 65 & 7 & 42 & 11 & 8 & 20 \\ 
\multicolumn{1}{l}{\textbf{Países Emergentes}} & \multicolumn{12}{c}{} \\ 
Baixo Rendimento & 653,6 & 976,2 & 1.127,4 & 2,2 & 2,1 & 38 & 58 & 4 & 66 & 6
& 11 & 32 \\ 
Média Baixa & 2.889,5 & 3.703,0 & 4.011,2 & 1,4 & 1,1 & 28 & 66 & 6 & 42 & 9
& 8 & 20 \\ 
Média Alta & 796,2 & 949,3 & 995,1 & 1,0 & 0,7 & 25 & 67 & 8 & 36 & 12 & 8 & 
17 \\ 
\multicolumn{1}{l}{\textbf{Países Desenvolvidos}} & 939,6 & 1.068,7 & 1.107,4
& 0,7 & 0,5 & 18 & 67 & 15 & 26 & 23 & 8 & 12 \\  \bottomrule
\end{tabular}
\end{sidewaystable}

正如您在图片中看到的,列与列之间的空间存在问题。OBS:代码中没有垂直线(红色)。我这样做是为了显示列与列之间的分隔。 在此处输入图片描述

另一个表的列居中存在问题。代码如下

{
\renewcommand{\arraystretch}{1}
\begin{sidewaystable}
%\begin{table}[tbp] \centering
\caption{Lista dos países segundo dados do Banco Mundial}\label{Tab:listpais}
\setlength{\tabcolsep}{0.5pt}
    \begin{tabular}{@{}c|lllll@{}}
\toprule   

\multirow{8}{*}{\begin{sideways}\textbf{Baixo Rendimento} \, \end{sideways}} 
& Afghanistan & Comoros & Haiti & Mali & Solomon Islands \\ 
& Bangladesh & Congo, Dem. Rep. & Kenya & Mauritania & Somalia \\ 
& Benin & Eritrea & Korea, Dem. Rep. & Mozambique & Tajikistan\\ 
& Burkina Faso & Ethiopia & Kyrgyz Republic & Myanmar & Tanzania\\ 
& Burundi & Gambia, The & Lao PDR & Nepal & Togo \\ 
& Cambodia & Ghana & Liberia & Niger & Uganda  \\ 
& Central African Republic & Guinea & Madagascar & Rwanda & Zambia \\ 
& Chad & Guinea-Bissau & Malawi & Sierra Leone & Zimbabwe \\ \hline
\multirow{12}{*}{\begin{sideways}\textbf{Rend. Médio-Baixo} \, \end{sideways}} 
& Angola & Egypt, Arab Rep. & Kosovo & Papua New Guinea & Timor-Leste \\ 
& Armenia & El Salvador & Lesotho & Paraguay & Tonga \\ 
& Belize & Georgia & Maldives & Philippines & Tunisia\\ 
& Bhutan & Guatemala & Marshall Islands & Samoa & Turkmenistan \\ 
& Bolivia & Guyana & Micronesia, Fed. Sts. & Sao Tome and Principe & Tuvalu \\ 
& Cameroon & Honduras & Moldova & Senegal & Ukraine \\ 
& Cape Verde & India & Mongolia & Sri Lanka & Uzbekistan \\ 
& China & Indonesia & Morocco & Sudan & Vanuatu \\ 
& Congo, Rep. & Iraq & Nicaragua & Swaziland & Vietnam \\ 
& Cote d'Ivoire & Jordan & Nigeria & Syrian Arab Republic & West Bank and Gaza \\ 
& Djibouti & Kiribati & Pakistan & Thailand & Yemen, Rep. \\ 
& Ecuador &  &  &  &  \\ \hline
\multirow{10}{*}{\begin{sideways}\textbf{Rend. Médio-Alto} \, \end{sideways}} 
& Albania & Bulgaria & Iran, Islamic Rep. & Mexico & South Africa \\ 
& Algeria & Chile & Jamaica & Montenegro & St. Kitts and Nevis \\ 
& American Samoa & Colombia & Kazakhstan & Namibia & St. Lucia \\ 
& Antigua and Barbuda & Costa Rica & Lebanon & Palau & St. Vincent and the Grenadines \\ 
& Argentina & Cuba & Libya & Panama & Suriname \\ 
& Azerbaijan & Dominica & Lithuania & Peru & Turkey \\ 
& Belarus & Dominican Republic & Macedonia, FYR & Romania & Uruguay \\ 
& Bosnia and Herzegovina & Fiji & Malaysia & Russian Federation & Venezuela, RB \\ 
& Botswana & Gabon & Mauritius & Serbia &  \\ 
& Brazil & Grenada & Mayotte & Seychelles & \\  \bottomrule 
\end{tabular}
%\end{table}
\end{sidewaystable}
}

这里你可以看到问题 在此处输入图片描述

答案1

对于第一个表格,我将通过以下方式修复布局:(a)使用l第一列的列类型,(b)将第 2 列至第 13 列中的数字与小数点对齐,以及(c)重新组织表格的标题以使其更具结构性并简化其内容。

关于第二个表:我建议你简单地插入一个明确的空间宏\,,三个sideways环境中的每一个。第二个表中的某些国家名称包含句号(“句号”),它们标记缩写而不是句子的结尾。我添加了一些标记以防止 LaTeX 加宽这些句号后面的空白。最后,我将第一个旋转单元格中的文本从 更改为Baixo RendimentoBaixo Rend.以使字符串更好地适应可用空间并与第一列中其他两个旋转字符串中的缩写单词“Rend.”对称。

在此处输入图片描述

在此处输入图片描述

\documentclass{article}
\usepackage[portuguese]{babel}
\usepackage[letterpaper,margin=1in]{geometry} % size of text block: 6.5" x 9"
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs,rotating,multirow,array,caption}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{dcolumn} % for aligning numbers on decimal markers
\newcolumntype{d}[1]{D,,{#1}}
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}
\begin{sidewaystable} 
\setlength{\tabcolsep}{3.5pt}
\centering \small
\caption{Nível da população} \label{nivelpopulacao2}

\begin{tabular}{@{}l *{3}{d{5.1}} *{2}{d{1.1}} *{7}{d{2.0}} @{}}
\toprule
& \multicolumn{3}{C{4cm}}{Pop.\ (milhões de pessoas) }
& \multicolumn{2}{C{2.5cm}}{Tx.\ cresc.\ médio anual (\%)}
& \multicolumn{3}{C{2.5cm}}{Distrib.\ etária en 2008 (\%)}
& \multicolumn{2}{C{2.5cm}}{Pop.\ ativa en 2008 (\%)}
& \multicolumn{1}{C{2.8cm}}{Tx.\ de Mortalidade \newline (por 1000 pessoas)}
& \multicolumn{1}{C{2.8cm}@{}}{Tx.\ de Natalidade \newline (por 1000 pessoas)} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-6} \cmidrule(lr){7-9} \cmidrule(lr){10-11} \cmidrule(lr){12-12} \cmidrule(l){13-13}
& \mc{1990} & \mc{2008} & \mc{2015} 
& \mc{1990--2008} & \mc{2008--15} 
& \mc{0--14} & \mc{15--64} & \mc{65$+$} 
& \mc{Jovem} & \mc{Idosa} & \mc{2008} & \mc{2008}\\
\midrule
\textbf{Mundo} & 5.278,9 & 6.697,3 & 7.241,2 & 1,3 & 1,1
& 27 & 65 & 7 & 42 & 11 & 8 & 20 \\
\textbf{Países Emergentes} & \multicolumn{12}{c}{} \\
\quad Baixo Rend. \ & 653,6 & 976,2 & 1.127,4 & 2,2 & 2,1 & 38 & 58 & 4 & 66 & 6
& 11 & 32 \\
\quad Média Baixa & 2.889,5 & 3.703,0 & 4.011,2 & 1,4 & 1,1 & 28 & 66 & 6 & 42 & 9
& 8 & 20 \\
\quad Média Alta & 796,2 & 949,3 & 995,1 & 1,0 & 0,7 & 25 & 67 & 8 & 36 & 12 & 8 &
17 \\
\textbf{Países Desenvolvidos} & 939,6 & 1.068,7 & 1.107,4
& 0,7 & 0,5 & 18 & 67 & 15 & 26 & 23 & 8 & 12 \\  
\bottomrule
\end{tabular}
\end{sidewaystable}

\renewcommand{\arraystretch}{1}
\begin{sidewaystable}
\centering
\caption{Lista dos países segundo dados do Banco Mundial} \label{Tab:listpais}

\begin{tabular}{@{} c|lllll @{}}
\toprule

\multirow{8}{*}{\begin{sideways}\textbf{Baixo Rend.}\end{sideways}\ }
& Afghanistan & Comoros & Haiti & Mali & Solomon Islands \\
& Bangladesh & Congo, Dem.\ Rep. & Kenya & Mauritania & Somalia \\
& Benin & Eritrea & Korea, Dem.\ Rep. & Mozambique & Tajikistan\\
& Burkina Faso & Ethiopia & Kyrgyz Republic & Myanmar & Tanzania\\
& Burundi & Gambia, The & Lao PDR & Nepal & Togo \\
& Cambodia & Ghana & Liberia & Niger & Uganda  \\
& Central African Republic & Guinea & Madagascar & Rwanda & Zambia \\
& Chad & Guinea-Bissau & Malawi & Sierra Leone & Zimbabwe \\ 
\midrule
\multirow{12}{*}{\begin{sideways}\textbf{Rend.\ Médio-Baixo}\end{sideways}\ }
& Angola & Egypt, Arab Rep. & Kosovo & Papua New Guinea & Timor-Leste \\
& Armenia & El Salvador & Lesotho & Paraguay & Tonga \\
& Belize & Georgia & Maldives & Philippines & Tunisia\\
& Bhutan & Guatemala & Marshall Islands & Samoa & Turkmenistan \\
& Bolivia & Guyana & Micronesia, Fed.\ Sts. & Sao Tome and Principe & Tuvalu \\
& Cameroon & Honduras & Moldova & Senegal & Ukraine \\
& Cape Verde & India & Mongolia & Sri Lanka & Uzbekistan \\
& China & Indonesia & Morocco & Sudan & Vanuatu \\
& Congo, Rep. & Iraq & Nicaragua & Swaziland & Vietnam \\
& Cote d'Ivoire & Jordan & Nigeria & Syrian Arab Republic & West Bank and Gaza \\
& Djibouti & Kiribati & Pakistan & Thailand & Yemen, Rep. \\
& Ecuador   \\ 
\midrule
\multirow{10}{*}{\begin{sideways}\textbf{Rend.\ Médio-Alto}\end{sideways}\ }
& Albania & Bulgaria & Iran, Islamic Rep. & Mexico & South Africa \\
& Algeria & Chile & Jamaica & Montenegro & St. Kitts and Nevis \\
& American Samoa & Colombia & Kazakhstan & Namibia & St.\ Lucia \\
& Antigua and Barbuda & Costa Rica & Lebanon & Palau & St.\ Vincent and the Grenadines \\
& Argentina & Cuba & Libya & Panama & Suriname \\
& Azerbaijan & Dominica & Lithuania & Peru & Turkey \\
& Belarus & Dominican Republic & Macedonia, FYR & Romania & Uruguay \\
& Bosnia and Herzegovina & Fiji & Malaysia & Russian Federation & Venezuela, RB \\
& Botswana & Gabon & Mauritius & Serbia &  \\
& Brazil & Grenada & Mayotte & Seychelles & \\  
\bottomrule
\end{tabular}
%\end{table}
\end{sidewaystable}

\end{document} 

答案2

这里与 Mico 的相同,但带有siunitx。第二个表格没有改变,因为 Mico 的解决方案已经很完美了。我将第一个表格调整为全字体大小。它现在占据了最大可用宽度。

% arara: pdflatex

\documentclass{article}
\usepackage[portuguese]{babel}
\usepackage[letterpaper,margin=1in]{geometry} % size of text block: 6.5" x 9"
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{booktabs,rotating,multirow,array,caption}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight}p{#1}}
\usepackage{siunitx}
\sisetup{% setup for portuguese
    ,output-decimal-marker={,}
    ,group-separator={.}
    ,group-four-digits
    }

\begin{document}
    \begin{sidewaystable} 
        \setlength{\tabcolsep}{4.05pt}
        \centering
        \caption{Nível da população} \label{nivelpopulacao2}
        \begin{tabular}{@{}l *{3}{S[table-format=4.1]} *{2}{S[table-format=1.1]} *{7}{S[table-format=2.0]}}
            \toprule
            & \multicolumn{3}{P{3.75cm}}{Pop.\ (milhões de pessoas) }
            & \multicolumn{2}{P{3.05cm}}{Tx.\ cresc.\ médio anual (\%)}
            & \multicolumn{3}{P{2.75cm}}{Distrib.\ etária en 2008 (\%)}
            & \multicolumn{2}{P{2.05cm}}{Pop.\ ativa en 2008 (\%)}
            & \multicolumn{1}{P{2.78cm}}{Tx.\ de Mortalidade en 2008  (por \num{1000} pessoas)}
            & \multicolumn{1}{P{2.8cm}}{Tx.\ de Natalidade en 2008 (por \num{1000} pessoas)} \\
            \cmidrule(lr){2-4} \cmidrule(lr){5-6} \cmidrule(lr){7-9} \cmidrule(lr){10-11} 
            & {1990} & {2008} & {2015} & {1990--2008} & {2008--15} 
            & {0--14} & {15--64} & {65$+$} 
            & {Jovem} & {Idosa} & & \\
            \midrule
            \textbf{Mundo} & 5278,9 & 6697,3 & 7241,2 & 1,3 & 1,1 & 27 & 65 & 7 & 42 & 11 & 8 & 20 \\
            \textbf{Países Emergentes} & & & & & & & & & & & & \\
            \quad Baixo Rend. & 653,6 & 976,2 & 1127,4 & 2,2 & 2,1 & 38 & 58 & 4 & 66 & 6   & 11 & 32 \\
            \quad Média Baixa & 2889,5 & 3703,0 & 4011,2 & 1,4 & 1,1 & 28 & 66 & 6 & 42 & 9 & 8 & 20 \\
            \quad Média Alta & 796,2 & 949,3 & 995,1 & 1,0 & 0,7 & 25 & 67 & 8 & 36 & 12 & 8 & 17 \\
            \textbf{Países Desenvolvidos} & 939,6 & 1068,7 & 1107,4 & 0,7 & 0,5 & 18 & 67 & 15 & 26 & 23 & 8 & 12 \\  
            \bottomrule
        \end{tabular}
    \end{sidewaystable}

    \begin{sidewaystable}
        \centering
        \caption{Lista dos países segundo dados do Banco Mundial} \label{Tab:listpais}      
        \begin{tabular}{@{} c|lllll @{}}
            \toprule            
            \multirow{8}{*}{\begin{sideways}\textbf{Baixo Rend.}\end{sideways}\ }
            & Afghanistan & Comoros & Haiti & Mali & Solomon Islands \\
            & Bangladesh & Congo, Dem.\ Rep. & Kenya & Mauritania & Somalia \\
            & Benin & Eritrea & Korea, Dem.\ Rep. & Mozambique & Tajikistan\\
            & Burkina Faso & Ethiopia & Kyrgyz Republic & Myanmar & Tanzania\\
            & Burundi & Gambia, The & Lao PDR & Nepal & Togo \\
            & Cambodia & Ghana & Liberia & Niger & Uganda  \\
            & Central African Republic & Guinea & Madagascar & Rwanda & Zambia \\
            & Chad & Guinea-Bissau & Malawi & Sierra Leone & Zimbabwe \\ 
            \midrule
            \multirow{12}{*}{\begin{sideways}\textbf{Rend.\ Médio-Baixo}\end{sideways}\ }
            & Angola & Egypt, Arab Rep. & Kosovo & Papua New Guinea & Timor-Leste \\
            & Armenia & El Salvador & Lesotho & Paraguay & Tonga \\
            & Belize & Georgia & Maldives & Philippines & Tunisia\\
            & Bhutan & Guatemala & Marshall Islands & Samoa & Turkmenistan \\
            & Bolivia & Guyana & Micronesia, Fed.\ Sts. & Sao Tome and Principe & Tuvalu \\
            & Cameroon & Honduras & Moldova & Senegal & Ukraine \\
            & Cape Verde & India & Mongolia & Sri Lanka & Uzbekistan \\
            & China & Indonesia & Morocco & Sudan & Vanuatu \\
            & Congo, Rep. & Iraq & Nicaragua & Swaziland & Vietnam \\
            & Cote d'Ivoire & Jordan & Nigeria & Syrian Arab Republic & West Bank and Gaza \\
            & Djibouti & Kiribati & Pakistan & Thailand & Yemen, Rep. \\
            & Ecuador   \\ 
            \midrule
            \multirow{10}{*}{\begin{sideways}\textbf{Rend.\ Médio-Alto}\end{sideways}\ }
            & Albania & Bulgaria & Iran, Islamic Rep. & Mexico & South Africa \\
            & Algeria & Chile & Jamaica & Montenegro & St.~Kitts and Nevis \\
            & American Samoa & Colombia & Kazakhstan & Namibia & St.~Lucia \\
            & Antigua and Barbuda & Costa Rica & Lebanon & Palau & St.~Vincent and the Grenadines \\
            & Argentina & Cuba & Libya & Panama & Suriname \\
            & Azerbaijan & Dominica & Lithuania & Peru & Turkey \\
            & Belarus & Dominican Republic & Macedonia, FYR & Romania & Uruguay \\
            & Bosnia and Herzegovina & Fiji & Malaysia & Russian Federation & Venezuela, RB \\
            & Botswana & Gabon & Mauritius & Serbia &  \\
            & Brazil & Grenada & Mayotte & Seychelles & \\  
            \bottomrule
        \end{tabular}
    \end{sidewaystable} 
\end{document} 

在此处输入图片描述

相关内容