0

I am quite new for the spreadtab package. I have prepared a MWE for my issues as:

\documentclass[handout]{beamer}
\usepackage{spreadtab}
%\input{diagrams}
\newcommand\dollarsign{\$}

\begin{document} \begin{frame}{MWE} \begin{spreadtab}{{tabular}{|r|r|r|r|}}\hline @test1 & - & 200 & 300 \ @test2 & - & 200x12 & @300x12 \ @test3 (pcm) & 0.99 & 1.99 & 2.99 \\hline \end{spreadtab} \end{frame} \end{document}

I cannot place a dollar sign inside the block of spreadtab as neither 0.99\$ nor 0.99\dollarsign. On the other hand, I would like to type 200x12 inside the cell without saying @200x12 (indicates it is text) for further column based calculation at the bottom row named as total. Current and desired scenario are placed here. The total row should be automatically calculated by the multiplication of test2 and test3 rows. What are your suggestions ? Thanks in advance!

ozturkib
  • 160
  • One solution is adding column for $ symbols and factors as people usually do in excel. – Zarko Feb 21 '22 at 14:12
  • @Zarko I got your suggestion, thanks for it. However, the size of the table increasing dramatically because of my actual case and the management is becoming more difficult to be honest :( Waiting for a bit more convenient suggestion. Thanks again. – ozturkib Feb 21 '22 at 15:15
  • First try your table make in excel. Than you will what is possible to do. A way, as ju try to do, is dead end. Sorry. – Zarko Feb 21 '22 at 15:20

1 Answers1

1

Explanation

To show the operation rather than the value, I found a workaround using the fact than spreadtab is made in a way that it will always compute a numerical values which is inside a command not matter what the command is. That is why I used a comment command that will not display the argument taken.

For the dollar sign, the use of :{} (the operator used to specify what the numerical value of a cell is) solves the issue by itself. You may want to take a look at spreadtab documentation to learn a bit more about it. I also took the initiative to replace your dollarsign command with a DS command in order to enhance the readability but it does not really matter.

Code

\documentclass[handout]{beamer}
\usepackage{spreadtab}
%\input{diagrams}
\newcommand\DS{\$}
\long\def\comment#1{}

\begin{document} \begin{frame}{MWE} \begin{spreadtab}{{tabular}{|r|r|r|r|}}\hline @test1 & - & 200 & 300 \ @test2 & - & $200\times12$\comment{:={20012}} & $300\times12$\comment{:={30012}} \ @test3 (pcm) & $:={0.99}\DS$ & $:={1.99}\DS$ & $:={2.99}\DS$ \\hline @total & $:={b2b3}\DS$ & $:={c2c3}\DS$ & $:={d2*d3}\DS$ \\hline \end{spreadtab} \end{frame} \end{document}

Output

LaTeX output

Enevevet
  • 772
  • Perfect answer! Thanks a lot. Absolutely what I need. Could you also explain the line of \long\def\comment#1{} with more details ? Is this also called \newcommand as well? Thanks @Enevevet – ozturkib Feb 22 '22 at 08:17
  • 1
    @ozturkib, I could have used \newcommand{\comment}{} (which is equivalent here in this case). \long\def are two primitive TeX commands while \newcommand was introduced in LaTeX. Here's a TeX.SE answer you might be interested if you want to learn about the actual dissimilarities. – Enevevet Feb 22 '22 at 08:39