3

I am trying to generate the following table:

enter image description here

My code is:

    \documentclass[12pt, a4paper]{article}
\usepackage{multirow}
\usepackage[labelfont=bf,labelsep=period]{caption}
\captionsetup[table]{skip = 1 pt}

    \begin{document}

    \begin{table}[!ht]\scriptsize
\caption{Comércio entre UE e Mercosul.}
\centering
\begin{tabular}{c c c c c c c c c}
    \toprule
    \multirow{3}{*}{\bf Itens} & \multicolumn{4}{c}{\bf Importação} & \multicolumn{4}{c}{Exportação} \\
    \cmidrule(r){2-5}\cmidrule(r){6-9}
    & {\bf 2013} & {\bf 2016} & {\bf 2013} & {\bf 2016} \\
    & \multicolumn{2}{c}{} & \multicolumn{2}{c}{} & \multicolumn{2}{c}{} & \multicolumn{2}{c}{} \\
   \cmidrule(r){2-3}\cmidrule(r){4-5}\cmidrule(r){6-7}\cmidrule(r){8-9}
    & Euro & \% & Euro & \% & Euro & \% & Euro & \% \\
    \hline    
        Total & 47.352 & 100,00 & 41.895 & 100,00 & 56.823 & 100,00 & 43.111 & 100,00 \\
        Produtos primários & 34.379 & 72,60 & 29.809 & 71,17 & 6.647 & 11,70 & 4.739 & 10,99 \\
        Manufaturados & 9.762 & 20,62 & 10.066 & 24,03 & 47.971 & 84,42 & 36.852 & 85,48 \\
        Outros produtos & 876 & 1,85 & 1.332 & 3,18 & 825 & 1,45 & 626 & 1,45 \\
        Outros & 2.336 & 4,93 & 687 & 1,64 & 1.379 & 2,43 & 894 & 2,07 \\
    \bottomrule
        \multicolumn{5}{l}{\tiny {\it Nota}: Mercosul 5 e União Europeia 28.} \\
        \multicolumn{5}{l}{\tiny Fonte: Eurostat comext (2017).} \\
\end{tabular}
\label{tab2}
    \end{table}

    \end{document}

Can anybody help me?

Thank you!

  • (please extend your code sniped to complete but small document beginning with\documentclass{...} and ending with \end{document} . we should know your page layout (is really needed so small fonts in table as can be observed in your code). – Zarko Mar 25 '18 at 1:14
  • If the values are in thousands of euros, you should not use a period for separating groups of digits, because this would make the figure very ambiguous: does 47.000 stand for 47 million euros or for 47000 euros? A period should never be used as digit group separator, but only as a decimal separator. – egreg Mar 25 '18 at 20:11
5

like this?

enter image description here

(red lines show text borders)

since you not given any information about you document, i design own, which may differ from yours a lot:

\documentclass{article}
% my preamble may be different from yours
\usepackage{geometry}
\usepackage[portuges]{babel}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage[skip=1ex]{caption}
\usepackage{booktabs,
            multirow,
            tabularx}

\begin{document}
    \begin{table}%[!ht]
\caption{Comércio entre UE e Mercosul.}
\label{tab2}
    \sisetup{%table-text-alignment=center, % used in table columns
             table-number-alignment=center,
             input-decimal-markers={,},
             output-decimal-marker={,},
             group-minimum-digits=4,
             group-separator={.}
             }
    \cmidrulekern=2pt
\begin{tabularx}{\linewidth}{X
                        *{4}{S[table-figures-integer=5, 
                               table-figures-decimal=0]
                             S[table-figures-integer=3,
                               table-figures-decimal=2]}
                            }
    \toprule
    & \multicolumn{4}{c}{\textbf{Importação}}
                      & \multicolumn{4}{c}{\textbf{Exportação}}     \\
    \cmidrule(lr){2-5}\cmidrule(lr){6-9}
\textbf{Itens}
    & {\textbf{2013}} & {\textbf{2016}} & {\textbf{2013}} & {\textbf{2016}}
    & {\textbf{2013}} & {\textbf{2016}} & {\textbf{2013}} & {\textbf{2016}} \\
   \cmidrule(lr){2-3}\cmidrule(lr){4-5}
   \cmidrule(lr){6-7}\cmidrule(lr){8-9}
    & {Euro}    & {\%}      & {Euro}    & {\%}
    & {Euro}    & {\%}      & {Euro}    & {\%}          \\
    \midrule
Total
    & 47 352    & 100,00    & 41 895    & 100,00
    & 56 823    & 100,00    & 43 111    & 100,00        \\
    \midrule
Produtos primários
    & 34 379    & 72,60     & 29 809    & 71,17
    &  6 647    & 11,70     &  4 739    & 10,99         \\
Manufaturados
    &  9 762    & 20,62     & 10 066    & 24,03
    & 47 971    & 84,42     & 36 852    & 85,48         \\
Outros produtos
    &   876     &  1,85     & 1 332     &  3,18
    &   825     &  1,45     &   626     &  1,45         \\
Outros
    & 2 336     &  4,93     &   687     &  1,64
    & 1 379     &  2,43     &   894     &  2,07         \\
    \bottomrule
\multicolumn{9}{p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth\relax}}{\footnotesize
    \textit{Nota}: Mercosul 5 e União Europeia 28.\newline
    \textit{Fonte}: Eurostat comext (2017).
                }
\end{tabularx}
    \end{table}
\end{document}
2

A few more suggestions in addition to Zarko’s fine answer.

  1. The setting of output-decimal-marker should be at a document level.
  2. A period should never be used for separating groups of digits, because it is ambiguous. Better leave the job to siunitx which will use a thin space.
  3. In the table we have a mixture of three to five digit numbers, so we add group-four-digits for uniformity.
  4. You can fit the table in \footnotesize, provided you squeeze it a bit.

The computation is easy, though it requires a bit of handwork. When the table is typeset with no adjustment to \tabcolsep, an overfull of 30.65004pt was reported. We have 16 intercolumn spaces to act on, because the left and right padding have been removed with @{}. Dividing the amount by 16 gives slightly less than 2pt, which can be safely subtracted to \tabcolsep.

In the first run, the argument to \addtolenght was set to 0pt; then I made the computation and fixed the length.

The setting is confined to the particular table environment, so it will not propagate to other tables.

\documentclass[12pt, a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage{siunitx,booktabs}
\usepackage{eurosym}

\usepackage[labelfont=bf,labelsep=period]{caption}
\captionsetup[table]{skip = 1pt}

\sisetup{output-decimal-marker={,}}

\begin{document}

\begin{table}[!htp]
\caption{Comércio entre UE e Mercosul.}\label{tab2}

\centering
\footnotesize

\addtolength{\tabcolsep}{-1.91563pt}
% Overfull was 30.65004; divided by 16 gives 1.9156275

\begin{tabular}{
  @{}
  l
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  @{}
}
\toprule
\textbf{Itens} &
\multicolumn{4}{c}{\bfseries Importação} &
\multicolumn{4}{c}{\bfseries Exportação} \\
\cmidrule(lr){2-5} \cmidrule(l){6-9}
& \multicolumn{2}{c}{\bfseries 2013} & \multicolumn{2}{c}{\bfseries 2016}
& \multicolumn{2}{c}{\bfseries 2013} & \multicolumn{2}{c}{\bfseries 2016} \\
\cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(l){8-9}
& {\euro/1000} & \% 
& {\euro/1000} & \% 
& {\euro/1000} & \% 
& {\euro/1000} & \% \\
\midrule
Total              & 47352 & 100,00 & 41895 & 100,00 & 56823 & 100,00 & 43111 & 100,00 \\
Produtos primários & 34379 &  72,60 & 29809 &  71,17 &  6647 &  11,70 &  4739 &  10,99 \\
Manufaturados      &  9762 &  20,62 & 10066 &  24,03 & 47971 &  84,42 & 36852 &  85,48 \\
Outros produtos    &   876 &   1,85 &  1332 &   3,18 &   825 &   1,45 &   626 &   1,45 \\
Outros             &  2336 &   4,93 &   687 &   1,64 &  1379 &   2,43 &   894 &   2,07 \\
\midrule[\heavyrulewidth]
\multicolumn{9}{@{}l@{}}{\scriptsize \textit{Nota}: Mercosul 5 e União Europeia 28.} \\
\multicolumn{9}{@{}l@{}}{\scriptsize \textit{Fonte}: Eurostat comext (2017).} \\
\end{tabular}

\end{table}

\end{document}

An alternative approach is to use tabular*:

\documentclass[12pt, a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage{siunitx,booktabs}
\usepackage{eurosym}

\usepackage[labelfont=bf,labelsep=period]{caption}
\captionsetup[table]{skip = 1pt}

\sisetup{output-decimal-marker={,}}

\begin{document}

\begin{table}[!htp]
\caption{Comércio entre UE e Mercosul.}\label{tab2}

\centering
\footnotesize

\setlength{\tabcolsep}{0pt}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  S[table-format=5.0,group-four-digits]
  S[table-format=3.2]
  @{}
}
\toprule
\textbf{Itens} &
\multicolumn{4}{c}{\bfseries Importação} &
\multicolumn{4}{c}{\bfseries Exportação} \\
\cmidrule(r{1pt}){2-5} \cmidrule(l{1pt}){6-9}
& \multicolumn{2}{c}{\bfseries 2013} & \multicolumn{2}{c}{\bfseries 2016}
& \multicolumn{2}{c}{\bfseries 2013} & \multicolumn{2}{c}{\bfseries 2016} \\
\cmidrule(r{1pt}){2-3}\cmidrule(l{1pt}r{1pt}){4-5}
\cmidrule(l{1pt}r{1pt}){6-7}\cmidrule(l{1pt}){8-9}
& {\euro/1000} & \% 
& {\euro/1000} & \% 
& {\euro/1000} & \% 
& {\euro/1000} & \% \\
\midrule
Total              & 47352 & 100,00 & 41895 & 100,00 & 56823 & 100,00 & 43111 & 100,00 \\
Produtos primários & 34379 &  72,60 & 29809 &  71,17 &  6647 &  11,70 &  4739 &  10,99 \\
Manufaturados      &  9762 &  20,62 & 10066 &  24,03 & 47971 &  84,42 & 36852 &  85,48 \\
Outros produtos    &   876 &   1,85 &  1332 &   3,18 &   825 &   1,45 &   626 &   1,45 \\
Outros             &  2336 &   4,93 &   687 &   1,64 &  1379 &   2,43 &   894 &   2,07 \\
\midrule[\heavyrulewidth]
\multicolumn{9}{@{}l@{}}{\scriptsize \textit{Nota}: Mercosul 5 e União Europeia 28.} \\
\multicolumn{9}{@{}l@{}}{\scriptsize \textit{Fonte}: Eurostat comext (2017).} \\
\end{tabular*}

\end{table}

\end{document}

The output is essentially the same for both approaches.

enter image description here

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.