使用 dcolumn 组织表格

使用 dcolumn 组织表格

我创建了这个表格。但是,文本不在中心。列按小数点标记排列,但列之间的间距不正确。我不明白 dcolumn 包。

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

答案1

我删除tabularx并减少了\tabcolsep一点,以便表格适合页面:

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

答案2

以下是使用该siunitx包的另一种可能性:

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

在此处输入图片描述

答案3

另一个解决方案是使用siunitxmakecell以及一个相对于小数点逗号\na居中的命令。我还添加了标题以确保标题的垂直间距更好,并简化了序言:

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

在此处输入图片描述

相关内容