4

I am trying to align the two columns of my table in the center (I want to keep the alignment of the decimal point) but I can't. Any advise?

enter image description here

\documentclass{article}
\usepackage{dcolumn,booktabs}
\begin{table}[H]
\centering
\caption{Example Table}
\label{table:4.2}
\resizebox{\textwidth}{!}{%
\newcolumntype{.}{D{.}{.}{6}}
\begin{tabular}{ . .}
\toprule
\multicolumn{2}{c}{\textbf{Two columns aligned at center and at the decimal point}} \\
\midrule
-0.000830   & -0.0013  \\
-0.000920   & -0.00088 \\
0.001769    & 0.00165  \\
0.000389    & -0.00255 \\
-0.001510   & -0.00155 \\
-0.001560   & -0.00176 \\
-0.003250   & 0.003311 \\
-0.001920   & -0.00022 \\
0.001769    & 0.00165  \\
-0.001560   & -0.00176 \\
-0.003250   & 0.003311 \\
\bottomrule
\end{tabular}
}
\end{table}
\end{document} 

1 Answers1

3

You have to do some computations by hand, due to the big header.

Here's a possible way. However, you should instead try and break the header into two rows. Avoid resizing tables.

\documentclass{article}
\usepackage{dcolumn,booktabs}

\newcolumntype{.}{D{.}{.}{6}}
\newlength{\mytablewidth}
\newlength{\mycolumnwidth}

\begin{document}

\begin{table}
\centering

\caption{Example Table}
\label{table:longhead}

\newcommand{\mytablehead}{%
  \textbf{Two columns aligned at center and at the decimal point}%
}
\settowidth{\mytablewidth}{\mytablehead}
\settowidth{\mycolumnwidth}{$-0.000000$}
\setlength{\tabcolsep}{\dimexpr(\mytablewidth-2\mycolumnwidth)/4}

\begin{tabular}{. .}
\toprule
\multicolumn{2}{@{}c@{}}{\mytablehead} \\
\midrule
-0.000830   & -0.0013  \\
-0.000920   & -0.00088 \\
0.001769    & 0.00165  \\
0.000389    & -0.00255 \\
-0.001510   & -0.00155 \\
-0.001560   & -0.00176 \\
-0.003250   & 0.003311 \\
-0.001920   & -0.00022 \\
0.001769    & 0.00165  \\
-0.001560   & -0.00176 \\
-0.003250   & 0.003311 \\
\bottomrule
\end{tabular}

\end{table}

\end{document} 

enter image description here

egreg
  • 1,121,712