[Tex/LaTex] Calculations in Table using spreadtab

calculationstables

When I use this piece,

\documentclass[a4paper,12pt]{report}
\usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.65in]{geometry}
\usepackage{multirow}
\usepackage{spreadtab}
\usepackage{url}
\usepackage[sc]{mathpazo}{setspace}
\begin{document}
\begin{table}[!htb]
\centering  
\caption{Sample} \vspace{3pt}
\begin{spreadtab}{{tabular}{|l|c|c|c|}}
\hline
@ b1 & 1 & 2 & 3 \\ \hline
@ b2 & 1 & 2 & 3 \\ \hline
@ \textbf{Sub Total} & \textbf{:={b1+b2}} 
&\textbf{:={c1+c2}}&\textbf{:={d1+d2}}\\ \hline
@ b5 & 1 & 2 & 3 \\ \hline
@ b6 & 1 & 2 & 3 \\ \hline
@ Sub Total & \STcopy{>}{b5+b4} &  & \\ \hline
@ b9 & 1 & 2 & 3 \\ \hline
@ b10 & 1 & 2 & 3 \\ \hline
@ Sub Total & \STcopy{>}{b7+b8} & & \\ \hline \hline
@ Total & \STcopy{>}{b3+b6+b9} & & \\ \hline
\end{spreadtab}
\label{tab:key}
\end{table}

Used in Table:~\ref{tab:key}
\end{document}

I get Partly what I wanted, When I add The rest to make,

\documentclass[a4paper,12pt]{article}
\usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.65in]{geometry}
\usepackage{multirow}
\usepackage{spreadtab}
\usepackage[sc]{mathpazo}
\usepackage[onehalfspacing]{setspace}
\begin{document}
\begin{table}[!htb]
\centering  
\caption{Sample} \vspace{3pt}
\begin{spreadtab}{{tabular}{|c|l|c|c|c|}}
\hline
\multirow{2}{*}{Sl No.} & \multirow{2}{*}{\textbf{Something}} & 
\multicolumn{3}{c|}{\textbf{something}}\\ \cline{3-5}
& & \textbf{X} & \textbf{Y} & \textbf{Z} \\  \hline
1 & @ b3 & 1 & 2 & 3 \\ \hline
2 & @ b4 & 1 & 2 & 3 \\ \hline
\multicolumn{1}{|c}{} & \multicolumn{1}{|l}{\textbf{Sub Total}} &  
\textbf{:={c3+c4}} &  \textbf{:={d3+d4}} &  \textbf{:={e3+e4}} \\     \hline
3 & @ b6 & 1 & 2 & 3 \\ \hline
4 & @ b7 & 1 & 2 & 3 \\ \hline
\multicolumn{1}{|c}{} & \multicolumn{1}{|l}{\textbf{Sub Total}} &  
\STcopy{>}{c6+c7}&  & \\ \hline
5 & @ b9 & 1 & 2 & 3 \\ \hline
6 & @ b10 & 1 & 2 & 3 \\ \hline
\multicolumn{1}{|c}{} & \multicolumn{1}{|l}{\textbf{Sub Total}} &  
\STcopy{>}{c9+c10} & & \\ \hline \hline
\multicolumn{1}{|c}{} & \multicolumn{1}{|l}{\textbf{Total}} &  
\STcopy{>}{c5+c8+c11} & & \\ \hline 
\end{spreadtab}
\label{tab:key}
\end{table}
  Used in Table:~\ref{tab:key}
\end{document}

I am getting errors.
Is there some way I can use the above code to get

enter image description here

or should everything be typed manually?

Best Answer

This is my code:

\documentclass[a4paper,12pt]{article}
\usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.65in]{geometry}
\usepackage{multirow}
\usepackage{spreadtab}
\usepackage[sc]{mathpazo}
\usepackage[onehalfspacing]{setspace}
\begin{document}
\begin{table}[!htb]
\centering
\caption{Sample} \vspace{3pt}
\begin{spreadtab}{{tabular}{|c|l|c|c|c|}}
\hline
@\multirow{2}{*}{Sl No.} & @\multirow{2}{*}{\textbf{Something}} &
@\multicolumn{3}{c|}{\textbf{something}}\\ \cline{3-5}
& & @\textbf{X} & @\textbf{Y} & @\textbf{Z} \\  \hline
1 & @ \STtextcell\ b3 & 1 & 2 & 3 \\ \hline
2 & @ \STtextcell\ b4 & 1 & 2 & 3 \\ \hline
@\multicolumn{1}{|c}{} & @\multicolumn{1}{l|}{\textbf{Sub Total}} &
\textbf{:={c3+c4}} &  \textbf{:={d3+d4}} &  \textbf{:={e3+e4}} \\     \hline
3 & @ \STtextcell\ b6 & 1 & 2 & 3 \\ \hline
4 & @ \STtextcell\ b7 & 1 & 2 & 3 \\ \hline
@\multicolumn{1}{|c}{} & @\multicolumn{1}{l|}{\textbf{Sub Total}} &
{\fontseries{b}\selectfont}\STcopy{>}{c6+c7} & \textbf{:={}} & \textbf{:={}}\\ \hline
5 & @ \STtextcell\ b9 & 1 & 2 & 3 \\ \hline
6 & @ \STtextcell\ b10 & 1 & 2 & 3 \\ \hline
@\multicolumn{1}{|c}{} & @\multicolumn{1}{l|}{\textbf{Sub Total}} &
{\fontseries{b}\selectfont}\STcopy{>}{c9+c10} & \textbf{:={}} & \textbf{:={}} \\ \hline \hline
@\multicolumn{1}{|c}{} & @\multicolumn{1}{l|}{\textbf{Total}} &
{\fontseries{b}\selectfont}\STcopy{>}{c5+c8+c11} & \textbf{:={}} & \textbf{:={}} \\ \hline
\end{spreadtab}
\label{tab:key}
\end{table}
  Used in Table:~\ref{tab:key}
\end{document} 

and this is the result:

enter image description here

Some remarks

  1. To print @ inside a spreadtab environment you have to use the command \STtextcell.
  2. Every cell that does not contain a calculation (or just a number) must contain the character @.
  3. If you want boldfaced cells when using \STcopy you have to add cells with empty calculations like \textbf{:={}}