3

I created this table. But, the text are not center. the columns are organized on decimal marker, but the space between columns are not correct. I don't understand the dcolumn packege.

   \documentclass[12pt,twoside,a4paper,openright]{report}
    \usepackage[portuguese]{babel}
    \usepackage[utf8]{inputenc}
    \usepackage[inner=3cm,outer=2cm,tmargin=2.0cm,bmargin=2.0cm, includefoot, includehead]{geometry}
    \usepackage{mathtools}
    \usepackage{booktabs, multicol, multirow}
    \usepackage{tabularx}
    \usepackage{dcolumn}
    \usepackage{layouts}
    \usepackage{makecell}
    \usepackage{threeparttable}

    \newcolumntype{d}[1]{D{.}{.}{#1}}
    \newcolumntype{,}{D{,}{,}{-2}}
    \newcommand{\mc}{\multicolumn}
    \newcolumntype{R}{>{\raggedleft\arraybackslash}X}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \newcolumntype{C}{>{\centering\arraybackslash}X}

    \begin{document}

    \begin{table}[htbp]
      \centering
      \caption{Composição quimica (wt\%) dos GCC's originais e modificados.}
      \begin{threeparttable}
      \begin{tabularx}{\textwidth}{l*{6}{d{-2}}}
    \cmidrule[0.8pt]{1-7}
      \textbf{Composição}  & \multicolumn{2}{c}{\textbf{H60}} & \multicolumn{2}{c}{\textbf{H90}} & \multicolumn{2}{c}{\textbf{H90 E}} \\
      \textbf{química (wt\%)}          &  \multicolumn{1}{X}{\centering Original} & \multicolumn{1}{X}{\centering Modificado} & \multicolumn{1}{X}{\centering Original} & \multicolumn{1}{X}{\centering Modificado} & \multicolumn{1}{X}{\centering Original} & \multicolumn{1}{X}{\centering Modificado}  \\
     \cmidrule{1-7}
    \textbf{Carbonato} & \multirow{2}{*}{103,2 \tnote{\textdagger}} & \multirow{2}{*}{55,5} & \multirow{2}{*}{97,4} &  \multirow{2}{*}{55,9} & \multirow{2}{*}{98,5} & \multirow{2}{*}{64,3} \\
    \textbf{de cálcio} &  & &  &  & &  \\
    \textbf{Água} & - & 3,9 & 0,2 & 3,2 & 0,3 & 2,5 \\
    \textbf{Sílica} & - & 40,6 & - & 39,6 & - & 30,6 \\
    \textbf{Impurezas} & - & - & 2,4 & 1,4 & 3,9 & 2,6 \\
     \cmidrule[0.8pt]{1-7}
      \end{tabularx}
      \begin{tablenotes}
        \item[\textdagger] Erro de medição.
        \end{tablenotes}
        \end{threeparttable}
      \label{tg_tabela}
    \end{table}
7
  • tabularx achieves the requested total width by adjusting the width of X columns but you have none, don't use tabularx just use a normal tabular Jul 2, 2014 at 15:06
  • I use tabularx because I have X colums. If I use tabular, it don't run
    – user46548
    Jul 2, 2014 at 15:12
  • There are no X columns in \begin{tabularx}{\textwidth}{l*{6}{d{-2}}} Jul 2, 2014 at 15:15
  • 1
    it is the table preamble that determines the column structure having X just in multicolumn entries can never really do anything reasonable (it's my code, I promise you if it ever does anything reasonable it's by luck:-) those entries absolutely should not be using X they should be using c Jul 2, 2014 at 15:18
  • 1
    don't use \centering with c (it does nothing c is like \mbox and is a one line entry with no paragraph so paragraph settings such as \centering have no effect. Conversely p and X are like \parbox and are for paragraphs of text so not usually good for numeric data Jul 2, 2014 at 15:29

3 Answers 3

2

I removed tabularx and reduced \tabcolsep a bit so that the table fits within the page:

 \documentclass[12pt,twoside,a4paper,openright]{report}
    \usepackage[portuguese]{babel}
    \usepackage[utf8]{inputenc}
    \usepackage[inner=3cm,outer=2cm,tmargin=2.0cm,bmargin=2.0cm, includefoot, includehead]{geometry}
    \usepackage{mathtools}
    \usepackage{booktabs, multicol, multirow}
    \usepackage{tabularx}
    \usepackage{dcolumn}
    \usepackage{layouts}
    \usepackage{makecell}
    \usepackage{threeparttable}

    \newcolumntype{d}[1]{D{.}{.}{#1}}
    \newcolumntype{,}{D{,}{,}{-2}}
    \newcommand{\mc}{\multicolumn}
    \newcolumntype{R}{>{\raggedleft\arraybackslash}X}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \newcolumntype{C}{>{\centering\arraybackslash}X}

    \begin{document}

    \begin{table}[htbp]
      \centering
\setlength\tabcolsep{4pt}
      \caption{Composição quimica (wt\%) dos GCC's originais e modificados.}
      \begin{threeparttable}
      \begin{tabular}{ld{3.1}*{5}{d{2.1}}}
    \cmidrule[0.8pt]{1-7}
      \textbf{Composição}  & \multicolumn{2}{c}{\textbf{H60}} & \multicolumn{2}{c}{\textbf{H90}} & \multicolumn{2}{c}{\textbf{H90 E}} \\
      \textbf{química (wt\%)}          &  \multicolumn{1}{c}{Original} & \multicolumn{1}{c}{Modificado} & \multicolumn{1}{c}{Original} & \multicolumn{1}{c}{Modificado} & \multicolumn{1}{c}{Original} & \multicolumn{1}{c}{Modificado}  \\
     \cmidrule{1-7}
    \textbf{Carbonato} & \multirow{2}{*}{103,2 \tnote{\textdagger}} & \multirow{2}{*}{55,5} & \multirow{2}{*}{97,4} &  \multirow{2}{*}{55,9} & \multirow{2}{*}{98,5} & \multirow{2}{*}{64,3} \\
    \textbf{de cálcio} &  & &  &  & &  \\
    \textbf{Água} & - & 3,9 & 0,2 & 3,2 & 0,3 & 2,5 \\
    \textbf{Sílica} & - & 40,6 & - & 39,6 & - & 30,6 \\
    \textbf{Impurezas} & - & - & 2,4 & 1,4 & 3,9 & 2,6 \\
     \cmidrule[0.8pt]{1-7}
      \end{tabular}
      \begin{tablenotes}
        \item[\textdagger] Erro de medição.
        \end{tablenotes}
        \end{threeparttable}
      \label{tg_tabela}

\noindent X\dotfill X
    \end{table}

\end{document}
3
  • ld{3.1}*{5}{d{2.1}} ....what means 3.1 and 2.1 ?
    – user46548
    Jul 2, 2014 at 15:52
  • The numbers in your columns do have 2 integers and 1 decimal (or 3 and 1 for the second column). dcolumn as well as siunitx in my answer need this information for propper centering.
    – LaRiFaRi
    Jul 2, 2014 at 17:57
  • @user46548 see the dcolumn documentation, it specifies how many digits to the left and right of the decimal point. Jul 2, 2014 at 20:37
2

Here is another possibility using the siunitx package:

% arara: pdflatex

\documentclass[12pt,twoside,a4paper,openright]{report}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[inner=3cm,outer=2cm,tmargin=2.0cm,bmargin=2.0cm, includefoot, includehead]{geometry}
\usepackage{booktabs, multicol}
\usepackage{threeparttable}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage{etoolbox}
\robustify\tnote
\newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}

\begin{document}
\begin{table}[htbp]
\sisetup{table-align-text-post = false}
\centering
\caption{Composição quimica (\si{wt\percent}) dos GCC's originais e modificados.}
    \begin{threeparttable}
        \begin{tabular}{lS[table-format=3.1]*{5}S[table-format=2.1]}
        \toprule
        \textbf{Composição} & \multicolumn{2}{c}{\textbf{H60}} & \multicolumn{2}{c}{\textbf{H90}} & \multicolumn{2}{c}{\textbf{H90 E}} \\
        \textbf{química (wt\%)} &  {Original} & {Modificado} & {Original} & {Modificado} & {Original} & {Modificado} \\
        \midrule
        \specialcell{\textbf{Carbonato}\\\textbf{de cálcio}} & 103,2 \tnote{\textdagger} & 55,5 & 97,4 &  55,9 & 98,5 & 64,3\\
        \textbf{Água} & {-} & 3,9 & 0,2 & 3,2 & 0,3 & 2,5 \\
        \textbf{Sílica} & {-} & 40,6 & {-} & 39,6 & {-} & 30,6 \\
        \textbf{Impurezas} & {-} & {-} & 2,4 & 1,4 & 3,9 & 2,6 \\
        \bottomrule
        \end{tabular}
        \begin{tablenotes}
        \item[\textdagger] Erro de medição.
        \end{tablenotes}
  \end{threeparttable}
  \label{tg_tabela}
\end{table}
\end{document}

enter image description here

1

Another solution with siunitx, makecell and a \na command to have centred with respect to the decimal comma. I also added caption to ensure a better vertical spacing of the caption and simplified the preamble:

\documentclass[12pt,twoside,a4paper,openright]{report}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[inner=3cm,outer=2cm,vmargin=2.0cm, includeheadfoot]{geometry}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{dcolumn}
\usepackage{layouts}
\usepackage{threeparttable}

\usepackage{caption}
\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}
\renewcommand{\theadalign}{lc}
\newcommand{\na}{{\hphantom{0}---}}
\newcommand{\naa}{{\hphantom{00}---}}

\usepackage{siunitx}
\sisetup{table-figures-integer = 2, table-figures-decimal = 1, table-number-alignment = center, output-decimal-marker = {,}}

\begin{document}

\begin{table}[htbp]
\centering\small
\caption{Composição quimica (wt\%) dos GCC's originais e modificados.}
\begin{threeparttable}
\begin{tabularx}{\textwidth}{X S[table-figures-integer=3] *{5}{S}}%
\cmidrule[0.8pt]{1-7}%[0.6ex]
\multirowthead{2}{Composição\\ química (wt\%)} & \multicolumn{2}{c}{\bfseries H60} & \multicolumn{2}{c}{\bfseries H90} & \multicolumn{2}{c}{\bfseries H90 E} \\[-1.5ex]
& {Original} & {Modificado} & {Original}& {Modificado} & {Original} & {Modificado} \\
%\addlinespace
\cmidrule{1-7}
\thead{Carbonato\cr de cálcio} & 103,2 {\,\tnote{\textdagger}} & 55,5 & 97,4 & 55,9 & 98,5 & 64,3 \\
Água & {\naa} & 3,9 & 0,2 & 3,2 & 0,3 & 2,5 \\
Sílica & \naa & 40,6 & \na & 39,6 & \na & 30,6 \\
Impurezas & \naa & \na & 2,4 & 1,4 & 3,9 & 2,6 \\
\cmidrule[0.8pt]{1-7}
\end{tabularx}
\begin{tablenotes}
\item[\textdagger] Erro de medição.
\end{tablenotes}
\end{threeparttable}
\label{tg_tabela}
\end{table}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .