Graphics, Figures & Tablesaligning numbers in tables

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dkaplan
Posts: 6
Joined: Tue May 19, 2009 4:18 pm

aligning numbers in tables

Post by dkaplan »

Greetings all,

I'm fairly new to using tables in LaTeX. I am finding it difficult to align columns of numbers (particularly if they have negative signs). I've attached an example which I hope will make clear my issue. Any advice would be greatly appreciated.

Thanks in advance.

David

Code: Select all

Code, edit and compile here:
\documentclass[12pt]{article}
\newcommand{\mb}[1]{\mbox{\boldmath $\bf#1$}}
\newcommand{\mbi}[1]{\mbox{\mathit{\boldmath $\bf#1$}}}
\setlength{\textwidth}{6.5in}\setlength{\textheight}{9.2in}
\setlength{\oddsidemargin}{-.05in} \setlength{\topmargin}{-.5in}
\usepackage{lscape}
\begin{document}
\pagestyle{empty}
\newpage
\begin{landscape}
\begin{table} [!hbp] \label{table3}
\begin{center} \small
\caption{$N_T$ = 1200}
\bigskip
\begin{tabular}{lcccccccrrrrrrrrrr}
\hline
&& $ICC_2$ && $ICC_2$ && $ICC_2$\\\\
&&0.0 ~~~0.1~~~ 0.2 ~~~0.3 ~~~0.4 && 0.0~~~0.1~~~ 0.2~~~ 0.3 ~~~0.4 && 0.0~~~ 0.1~~~ 0.2 ~~~0.3 ~~~0.4\\
\hline\\
&& 15 W/80 B && 20 W/60 B && 30 W/ 40 B\\\\
&& 0 ~~~~-4 ~~~~-9 ~~~~-12 ~~~~-15 &&0 ~~~~-3 ~~~~-7 ~~~~-11 ~~~~-14 && 0 ~~~~-3 ~~~~-8 ~~~~-11~~~~-15\\
&& -3 ~~~~-8 ~~~~-11 ~~~~-13 ~~~~-16 && -2 ~~~~-7 ~~~~-10 ~~~~-13 ~~~~-15 &&-2 ~~~~-7 ~~~~-10 ~~~~-13 ~~~~-15\\
$ICC_1$&& -6 ~~~~-9 ~~~~-11 ~~~~-14 ~~~~-17 && -5 ~~~~-8 ~~~~-11 ~~~~-13 ~~~~-16 && -5 ~~~~-9 ~~~~-11 ~~~~-13 ~~~~-16\\
&&-8 ~~~~-11 ~~~~-13 ~~~~-15 ~~~~-17 && -7 ~~~~-10 ~~~~-12 ~~~~-13 ~~~~-16 && -7 ~~~~-10 ~~~~-12 ~~~~-14 ~~~~-16\\
&&6 ~~~~-10 ~~~~-13 ~~~~-14 ~~~~-16 ~~~~-17 && -9 ~~~~-11 ~~~~-13 ~~~~-14 ~~~~-16 && -9 ~~~~-12 ~~~~-13 ~~~~-14 ~~~~-16\\\\\\
&& 40 W/30 B && 60 W/20 B && 80 W/ 15 B\\\\
&& $0$ ~~~{-4} ~~~-8 ~~~-12 ~~~-15 && 0 ~~~-4 ~~~-8 ~~~-12 ~~~-15 && 0 ~~~-5 ~~~-8 ~~~-13 ~~~-15\\
&& $-3$ ~~~{-8} ~~~-10 ~~~-14 ~~~-16 &&-3 ~~~-7 ~~~-11 ~~~-13 ~~~-16 &&-3 ~~~-8 ~~~-11 ~~~-14 ~~~-16\\
$ICC_1$&& $-5$ ~~~{-9} ~~~-11 ~~~-14 ~~~-16 && -5 ~~~-9 ~~~-12 ~~~-14 ~~~-16 && -5 ~~~-10 ~~~-12 ~~~-14 ~~~-17\\
&& $-8$ ~~~-11 ~~~-13 ~~~-14 ~~~-16 &&-8 ~~~-11 ~~~-12 ~~~-15 ~~~-17 &&-8 ~~~-11 ~~~-13 ~~~-15 ~~~-16\\
&& $-9$ ~~~-12 ~~~-13 ~~~-15 ~~~-16 &&-10 ~~~-12 ~~~-13 ~~~-15 ~~~-17 &&-10 ~~~-12 ~~~-14 ~~~-15 ~~~-17\\\\
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Recommended reading 2024:

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

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

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

aligning numbers in tables

Post by phi »

Hi,

use the siunitx package for everything related to numbers or units.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

aligning numbers in tables

Post by localghost »

The most noticeable mistake you do is that you are declaring 1*l+7*c+10*r=18 columns in the head of your table but you only use seven of them. You need to restructure your table completely. The [url=hzttp://ctan.org/pkg/siunitx]siunitx[/url] package suggested by phi will help you.

Code: Select all

Code, edit and compile here:
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{fontenc}
\usepackage{babel}
\usepackage{includeheadfoot,margin=2cm]{geometry}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage{siunitx}
\begin{document}
\begin{sidewaystable}
\caption{Table caption}\label{tab:icc}
\centering\scriptsize
\begin{tabular}{%
c
*{5}{S[tabnumalign=centre,tabformat=+2.1]}
@{\qquad}
*{5}{S[tabnumalign=centre,tabformat=+2.1]}
@{\qquad}
*{5}{S[tabnumalign=centre,tabformat=+2.1]}
} \toprule
& \multicolumn{5}{c}{ICC\textsubscript{2}} & \multicolumn{5}{c}{ICC\textsubscript{2}} & \multicolumn{5}{c}{ICC\textsubscript{2}} \\ \addlinespace
& 0.0 & 0.1 & 0.2 & 0.3 & 0.4 & 0.0 & 0.1 & 0.2 & 0.3 & 0.4 & 0.0 & 0.1 & 0.2 & 0.3 & 0.4 \\ \midrule[0.8pt]
& \multicolumn{5}{c}{15 W/80 B} & \multicolumn{5}{c}{20 W/60 B} & \multicolumn{5}{c}{30 W/ 40 B} \\ \addlinespace
& 0 & -4 & -9 & -12 & -15 & 0 & -3 & -7 & -11 & -14 & 0 & -3 & -8 & -11 & -15 \\
& -3 & -8 & -11 & -13 & -16 & -2 & -7 & -10 & -13 & -15 & -2 & -7 & -10 & -13 & -15\\
ICC\textsubscript{1} & -6 & -9 & -11 & -14 & -17 & -5 & -8 & -11 & -13 & -16 & -5 & -9 & -11 & -13 & -16 \\
& -8 & -11 & -13 & -15 & -17 & -7 & -10 & -12 & -13 & -16 & -7 & -10 & -12 & -14 & -16 \\
& -10 & -13 & -14 & -16 & -17 & -9 & -11 & -13 & -14 & -16 & -9 & -12 & -13 & -14 & -16 \\ \midrule
& \multicolumn{5}{c}{40 W/30 B} & \multicolumn{5}{c}{60 W/20 B} & \multicolumn{5}{c}{80 W/ 15 B} \\ \addlinespace
& 0 & -4 & -8 & -12 & -15 & 0 & -4 & -8 & -12 & -15 & 0 & -5 & -8 & -13 & -15 \\
& -3 & -8 & -10 & -14 & -16 & -3 & -7 & -11 & -13 & -16 & -3 & -8 & -11 & -14 & -16 \\
ICC\textsubscript{1} & -5 & -9 & -11 & -14 & -16 & -5 & -9 & -12 & -14 & -16 & -5 & -10 & -12 & -14 & -17 \\
& -8 & -11 & -13 & -14 & -16 & -8 & -11 & -12 & -15 & -17 & -8 & -11 & -13 & -15 & -16 \\
& -9 & -12 & -13 & -15 & -16 & -10 & -12 & -13 & -15 & -17 & -10 & -12 & -14 & -15 & -17 \\ \bottomrule
\end{tabular}
\end{sidewaystable}
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
However, it seems that columns are a bit too wide.


Best regards
Thorsten
Post Reply