Graphics, Figures & TablesAligning columns to plus/minus symbol and centering

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jyb
Posts: 2
Joined: Mon Dec 13, 2010 4:22 am

Aligning columns to plus/minus symbol and centering

Post by jyb »

Hi all,

I am trying to make a table where the data has plus/minus symbols and columns are aligned to the plus/minus symbols. I've managed to do the aligning, but the column headings are not centered over the data columns. I've attached the code below. Thanks for your help!

Jon

Code: Select all

\documentclass[12pt]{report}
\usepackage{booktabs}
\begin{document}
\begin{table}
\begin {center}
\begin{tabular}{c r@{$\pm$}l r@{$\pm$}l r@{$\pm$}l}
\toprule
\textit{Sample} 
& \multicolumn{2}{c}{\textit{Duration (frames)}} 
& \multicolumn{2}{c}{\textit{Uncorrected Intensity}}
& \multicolumn{2}{c}{\textit{S/B Ratio}}\\
\midrule
\textbf{3} & 57&44 & 13009&1442 & 2.0&0.3\\
\textbf{2} & 29&10 & 13875&1911 & 2.1&0.5)\\
Blank & 14&8 & 10451&338 & 1.8&0.2\\
\bottomrule
\end{tabular}
\caption{Summary of statistics from analysis of all three samples.}
\end {center}
\end{table}
\end{document}
Last edited by jyb on Thu Dec 16, 2010 8:27 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Aligning columns to plus/minus symbol and centering

Post by frabjous »

You might try an unconventional usage of the dcolumn package, like so:

Code: Select all

\documentclass[12pt]{report}
\usepackage{booktabs}
\usepackage{dcolumn}
\begin{document}
\begin{table}
\begin {center}
\begin{tabular}{c D{,}{\pm}{-1} D{,}{\pm}{-1} D{,}{\pm}{4.4} }
\toprule
\textit{Sample}
& \multicolumn{1}{c}{\textit{Duration (frames)}}
& \multicolumn{1}{c}{\textit{Uncorrected Intensity}}
& \multicolumn{1}{c}{\textit{S/B Ratio}}\\
\midrule
\textbf{3} & 57,44 & 13009,1442 & 2.0,0.3\\
\textbf{2} & 29,10 & 13875,1911 & 2.1,0.5\\
Blank & 14,8 & 10451,338 & 1.8,0.2\\
\bottomrule
\end{tabular}
\caption{Summary of statistics from analysis of all three samples.}
\end {center}
\end{table}
\end{document}
(This would be perhaps improved with some tweaking. Read the documentation for how to use it.)

As is, it generates this:
dcol.png
dcol.png (9.15 KiB) Viewed 15960 times
jyb
Posts: 2
Joined: Mon Dec 13, 2010 4:22 am

Re: Aligning columns to plus/minus symbol and centering

Post by jyb »

Thanks, this looks great! I may not need to do any tweaking, but I'll check out the documentation to see what else I can do with it (it can be hard to resist playing around with LaTeX :) ).
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Aligning columns to plus/minus symbol and centering

Post by localghost »

Now that the problem is solved, please be so kind and mark the topic accordingly as written in Section 3 of the Board Rules (to be read before posting). Please keep that in mind for the future so that further reminders will not be necessary.


Best regards and welcome to the board
Thorsten
Post Reply