I am trying to create a table with uncertainties using the following code:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{table}[!ht]
\begin{center}
\label{tab:table1}
\begin{tabular}{l|r|r}
\textbf{First Column Name} & \textbf{Second Column Name} & \textbf{Third Column Name} \\
& Sub Name 2 & Sub Name 3 \\
%
\hline
Row 1 & 1.00\, $\pm$\, 0.02 & - \\
Row 2 & 1.55\, $\pm$\, 0.05 & 50\% \,$\pm$\, 5\% \\
\hspace{2mm}Sub Row 3 & 1.20\, $\pm$\, 0.15 & -12.2\% \,$\pm$\; 1.2\% \\
Row 4 & 10.0\, $\pm$\, 1.1 & - \\
Row 5 & - & -85\% \,$\pm$\, 2\% \\
\hspace{2mm}Sub Row 6 & 2.6 \, $\pm$\, 0.9 & -20.0\% \,$\pm$\, 0.1\% \\
\end{tabular}
\end{center}
\caption{My caption text.}
\end{table}
\end{document}
which produces this table:
I have several problems with regards to formatting:
- How can the alignment of numbers within a column be controlled? I would like the ± symbols to all be aligned within a column.
- Is there a way that the column titles ("Second Column Name" and "Sub Name 2") can be centered, whilst leaving the numbers in that column right-aligned?
- What code would I use to make "Second Column Name" wrap onto a new line (still keeping "Sub Name 2" on a separate line though). At the moment, the column is much wider than it needs to be.
I have tried following several answers (for example here) which recommend the siunitx
package, but within each column I do not always have the same number of decimal places in every row, and was struggling to make it work. Is that package really the best way to go here, or are there simple tweaks that can be done to this example to make it work? Thanks.