Information and discussion about graphics, figures & tables in LaTeX documents.
casperyc
Posts: 50 Joined: Thu Oct 15, 2009 11:23 pm
Post
by casperyc » Fri Jan 01, 2010 9:36 pm
Code: Select all
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{multicol,multirow}
\usepackage[left=1cm,right=1cm]{geometry}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{*{5}{c} rr}
Year&Premium&Expenses&Acc.of $P_t-e_t$&Death Cost& \multicolumn{1}{c}{Survival Cost} & \multicolumn{1}{c}{In force expected net $CF$}\\[1.2ex]
$t$&$P_t$&$e_t$&$(P_t-e_t)(10.8)$&$10,000q_{62+t-1}$& \multicolumn{1}{c}{$p_{62+t-1}S_t$} & \multicolumn{1}{c}{$(CF)_t$}\\[1.2ex]
1&3,091,79&92.75&3238.96&101.12&0.00&3137.84\\
2&3,091,79&92.75&3238.96&113.44&0.00&3125.52\\
3&3,091,79&92.75&3238.96&127.16&9872.84&-6761.04
\end{tabular}
\end{table}
\end{document}
==========================================================
how do i make the "numbers" centered as well in the table?
keeping the decimals aligned
table.jpg (17.44 KiB) Viewed 6180 times
Thanks!
casper
NEW: TikZ book now 40% off at Amazon.com for a short time.
freethebee
Posts: 6 Joined: Tue Sep 08, 2009 7:21 pm
Post
by freethebee » Fri Jan 01, 2010 10:58 pm
Hi,
Have a look at the siunitx package, section 5.1 of the manual.
php1ic
Posts: 192 Joined: Wed Jan 28, 2009 8:17 pm
Post
by php1ic » Fri Jan 01, 2010 11:00 pm
Use @{} to specify what is between the columns and split the decimals over 2 columns separated by the decimal point.
Code: Select all
\begin{table}[h]
\centering
\begin{tabular}{r@{.}lr@{.}l}
\multicolumn{2}{c}{Centered} & \multicolumn{2}{c}{Stuff}\\
1234&56&0&005\\
0&12&234&67
\end{tabular}
\end{table}
josephwright
Site Moderator
Posts: 814 Joined: Tue Jul 01, 2008 2:19 pm
Post
by josephwright » Fri Jan 01, 2010 11:21 pm
Using the siunitx approach, I'd do something like:
Code: Select all
\documentclass{article}
\usepackage{siunitx,booktabs}
\usepackage[left=1cm,right=1cm]{geometry}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{
S[tabformat=1]
S[tabformat=6]
S[tabformat=4.2]
S[tabformat=3.2]
S[tabformat=4.2]
S[tabformat=+4.2]
}
\toprule
{Year} & {Premium} & {Acc.~of $P_t-e_t$} & {Death Cost} & {Survival Cost} & {In force expected net $CF$} \\
{$t$} & {$P_t$} & {$(P_t-e_t)(10.8)$} & {$10000q_{62+t-1}$} & {$p_{62+t-1}S_t$} & {$(CF)_t$} \\
\midrule
1 & 309179 & 3238.96 & 101.12 & 0.00 & 3137.84 \\
2 & 309179 & 3238.96 & 113.44 & 0.00 & 3125.52 \\
3 & 309179 & 3238.96 & 127.16 & 9872.84 & -6761.04 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Joseph Wright
casperyc
Posts: 50 Joined: Thu Oct 15, 2009 11:23 pm
Post
by casperyc » Wed Jan 06, 2010 4:58 pm
josephwright wrote: Using the siunitx approach, I'd do something like:
Code: Select all
\documentclass{article}
\usepackage{siunitx,booktabs}
\usepackage[left=1cm,right=1cm]{geometry}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{
S[tabformat=1]
S[tabformat=6]
S[tabformat=4.2]
S[tabformat=3.2]
S[tabformat=4.2]
S[tabformat=+4.2]
}
\toprule
{Year} & {Premium} & {Acc.~of $P_t-e_t$} & {Death Cost} & {Survival Cost} & {In force expected net $CF$} \\
{$t$} & {$P_t$} & {$(P_t-e_t)(10.8)$} & {$10000q_{62+t-1}$} & {$p_{62+t-1}S_t$} & {$(CF)_t$} \\
\midrule
1 & 309179 & 3238.96 & 101.12 & 0.00 & 3137.84 \\
2 & 309179 & 3238.96 & 113.44 & 0.00 & 3125.52 \\
3 & 309179 & 3238.96 & 127.16 & 9872.84 & -6761.04 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Thanks, I believe this is something I was looking for, much easier than using @{}
How can I apply
\num[digitsep=comma]{12345}
this, the comma seperator to a speacific column? e.g. the first column in the table above?
Thanks.
josephwright
Site Moderator
Posts: 814 Joined: Tue Jul 01, 2008 2:19 pm
Post
by josephwright » Wed Jan 06, 2010 5:15 pm
casperyc wrote:
How can I apply
\num[digitsep=comma]{12345}
this, the comma seperator to a speacific column? e.g. the first column in the table above?
Code: Select all
\begin{tabular}{
S[tabformat=1]
S[tabformat=6,digitsep=comma]
S[tabformat=4.2]
S[tabformat=3.2]
S[tabformat=4.2]
S[tabformat=+4.2]
}
(I guess you mean column 2, not column 1!)
Joseph Wright
casperyc
Posts: 50 Joined: Thu Oct 15, 2009 11:23 pm
Post
by casperyc » Wed Jan 06, 2010 5:19 pm
josephwright wrote: casperyc wrote:
How can I apply
\num[digitsep=comma]{12345}
this, the comma seperator to a speacific column? e.g. the first column in the table above?
Code: Select all
\begin{tabular}{
S[tabformat=1]
S[tabformat=6,digitsep=comma]
S[tabformat=4.2]
S[tabformat=3.2]
S[tabformat=4.2]
S[tabformat=+4.2]
}
(I guess you mean column 2, not column 1!)
yes, you are absolutely right!
that's why i couldnt get it even though i tried
S[tabformat=1,digitsep=comma]
which was a bit tooo careless
I am reading your siunitx package at the moment.
Thanks!
casperyc
Posts: 50 Joined: Thu Oct 15, 2009 11:23 pm
Post
by casperyc » Wed Jan 06, 2010 5:39 pm
Code: Select all
\begin{table}[H]
\centering
\begin{tabular}{
S[tabformat=1]
S[tabformat=4.2,digitsep=comma]
S[tabformat=4.2,digitsep=comma]
S[tabformat=4.2,digitsep=comma]
S[tabformat=1.5]
S[tabformat=4.2]
S[tabformat=+3.2]
}
{Year} &
{In force expected} &
{Reserve at} &
{Acc.~of reserve} &
{Survival} &
{In force expected reserve} &
{Profit} \\[1.2ex]
%
&
{net $CF$} &
{start of year} &
{at start of year} &
{Prob.} &
{at end of year} &
{vector} \\[1.2ex]
%
{ $t$ } &
{ $(CF)_t$ } &
{ ${}_{t-1}V$ } &
{ $_{t-1}V(1.08)$ } &
{ $p_{62+t-1}$ } &
{ $p_{62+t-1}{}_tV$ } &
{ $(PRO)_t$ } \\[1.2ex]
%
1&3137.84&0.00&0.00&0.98989&3139.10&-1.26\\
2&3125.52&3171.16&3424.85&0.98866&6426.11&124.26\\
3&-6761.04&6499.82&7019.81&0.98728&0.00&258.77
\end{tabular}
\end{table}
numbers such as 3171.16
how do i get it to 3,171.16
i have tried apply S[tabformat=4.2,digitsep=comma] to its column
does not work
Thanks.
josephwright
Site Moderator
Posts: 814 Joined: Tue Jul 01, 2008 2:19 pm
Post
by josephwright » Wed Jan 06, 2010 6:41 pm
You need to turn on the "sepfour" option. As you applying the same settings globally to the table, it will be faster to put them in only once:
Code: Select all
\begin{table}
\sisetup{digitsep=comma,sepfour}
\begin{tabular} ...
Joseph Wright
casperyc
Posts: 50 Joined: Thu Oct 15, 2009 11:23 pm
Post
by casperyc » Wed Jan 06, 2010 6:55 pm
josephwright wrote: You need to turn on the "sepfour" option. As you applying the same settings globally to the table, it will be faster to put them in only once:
applying
globally,
the deciamls got the comma as well.
e.g.
0.989,89
0.987,28
is there another command that can keep the decimals as
0.989 89
0.987 28
space seperated?
Thanks.