4

Could you help me formatting these two tables? I'm close to submit my thesis, but I found some problem in formatting these tables.

This is the preamble I'm using

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

The first one is about the space between columns. This is the code

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

As you can see in the image, It has a problem with space between column. OBS: there is no vertical line (red) in the code. I did it in order to show the separation between columns. enter image description here

Another table has a problem with centering the column. the code is this

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

and here, you can see the problem enter image description here

  • You could help us to help you adding a preamble to make a MWE as surely you know is required in the questions submitted here. – Aradnix May 7 '15 at 5:04
  • @Aradnix thank you for your observation. I did it. – Gilson May 7 '15 at 5:13
7

Regarding the first table, I would fix the layout by (a) using the l column type for the first column, (b) aligning the numbers in columns 2 thru 13 on the decimal markers, and (c) reorganizing the table's header to give it more structure as well as to simplify its contents.

Regarding the second table: I suggest you simply insert an explicit space macro, \, after each of the three sideways environments. Some of the country names in the second table contain periods ("full stops") that mark abbreviations rather than ends of sentences. I've added some markup to keep LaTeX from widening the whitespace that follows these periods. Finally, I changed the text in the first rotated cell from Baixo Rendimento to Baixo Rend., in order to make the string fit better in the available space and for symmetry with the abbreviated word "Rend." in the other two rotated strings in the first column.

enter image description here

enter image description here

\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} 
  • suggestion for second table -- allow a really long name to go to two lines, with the second line slightly indented to indicate it's a continuation. that would allow the width of the columns to be a little more even, and wouldn't even make the table longer, since it's only "st. vincent and the grenadines" that would get split. – barbara beeton May 7 '15 at 16:11
  • 1
    @barbarabeeton - I noticed too that the five data columns aren't exactly equally wide. However, as you observed as well, only one country name ("St. Vincent and the Grenadines") would get split if one adopted equal-width tables. However, since that name occurs in the final column, the aesthetic gain due to column width uniformity would be diminished by an over "looser look" of the table. That's why I kept the OP's l column type for the five data columns in the second table. – Mico May 7 '15 at 22:50
  • @LaRiFaRi - Many thanks for the comments (given below your answer). They led me to (i) widen the final two columns of the first table and (ii) reorganize the header material slightly (viz., place "2008" in the previously empty sub-header). As a result, the main header material of the final two columns now fits in two lines -- compared to four lines in the earlier version. Definitely an improvement! :-) – Mico May 7 '15 at 23:57
  • @Mico - The last time you helped me in this question I found a problem, but I forgot it. Today I need it. the problem is the portuguese babel. I'm using: \usepackage[latin1]{inputenc} \usepackage[portuges]{babel} but you suggested me this: \usepackage[portuguese]{babel} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} But yours don't work in my tex file? Could you tell me why? – Gilson Aug 21 '15 at 19:48
  • @Gilson - I'm afraid your comment is quite terse, leaving me unsure what may be going on. For sure, "[some solution] do[esn]'t work in my tex file" is not very informative. Please post a new query (possibly with back reference to this older query) explaining what it is you're trying to achieve and what exactly you've tried so far. Thanks. – Mico Aug 21 '15 at 19:58
7

Here the same thing as from Mico but with siunitx. The second table has not changed as the solution of Mico was already perfect. I adapted the first one to full font-size. It occupies the maximum available width now.

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

enter image description here

  • You may want to add a discussion of the relative merits of using the dcolumn and siunitx packages for the purpose of aligning numbers in tabular columns on their respective decimal markers. Is the second table (more or less) the same as in my answer? If so, you may want to mention the fact explicitly (or omit the table from your posting?). – Mico May 7 '15 at 11:28
  • @Mico Yes, it is almost the same. I got rid of the image. Discussions about the two packages can be found elsewhere. Here, it is just personal taste. Main changes just have been \RaggedRight, lmodern, omitting \small... not so much. – LaRiFaRi May 7 '15 at 13:24
  • some of the column titles in the heading would look better (and perhaps be more easily read) if the lines were broken differently. that might be forced by a little \mboxing, or an explicit new line indicator (not \\). – barbara beeton May 7 '15 at 16:07
  • i think that ragged center might be better for the column headings rather than \RaggedRight. (the ragged part is certainly desirable!) – barbara beeton May 7 '15 at 16:09
  • @LaRiFaRi, thank you too for this suggestion!!! – Gilson May 7 '15 at 18:44

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.