1

I use as template macro from this articale: Add Rows to Table With Macro. All work fine if values in cells not to calculate. But othewise results of calculation is the same for each row. How to avoid this problem? Log-file ref: https://yadi.sk/i/vgnoGKni3SLZGD.

   \documentclass[oneside,final,14pt]{report}
\usepackage[T1,T2A]{fontenc}
 \usepackage{mathptmx}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{extsizes}
\usepackage{mathtext}
\usepackage{underscore}
\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{titlesec}
\usepackage{times}
\usepackage {listing}
\usepackage{microtype}
\usepackage{xstring}
\usepackage {etoolbox}
\usepackage {expl3}
\usepackage[parse-numbers=true,round-precision=4,round-mode=figures,exponent-product=\cdot]{siunitx}
\usepackage{siunitx} % Provides the \SI{}{} command for typesetting SI units, набор значений единиц измерения
\usepackage {calculator}
\usepackage {fp}
\usepackage {tikz}
\usepackage[space]{grffile}% дополнение, чтобы были пробелы в именах
\grffilesetup{% дополнение, чтобы имена файлов могли быть кириллицей (под Windows)
  encoding,
  filenameencoding=cp1251
}

\titleformat{\chapter}[display]{\normalfont\bfseries}{}{0pt}{\huge}

\titlespacing*{\chapter}{0pt}{-50pt}{40pt}

 \usepackage{verbatim}
 %Поддержка отступов
\usepackage{vmargin}
% Работа с надписями
\usepackage{boxedminipage}
%Для окрашивания текста и не только
\usepackage{xparse}
\usepackage[titletoc,toc,page]{appendix}
\usepackage{ifthen}
\usepackage{arrayjobx}
\usepackage {ifpdf}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
%Ссылки и закладки содержание вса��вка текста
\usepackage{filecontents}
 %control over PDF bookmarks
\usepackage[nameinlink]{cleveref}

\usepackage{indentfirst}
\usepackage{titlesec}
\usepackage{soul}
%Математический пакет
\usepackage{amssymb,amsmath}

\usepackage {rotating}
\usepackage{amscd}
%Для обращения к цвету по имени
\usepackage{color}
\usepackage{xcolor,colortbl}
\usepackage{tabularx}

\usepackage{amssymb,amsfonts,amsmath,amsthm} % математические дополнения от АМС
\usepackage{indentfirst} % отделять первую строку раздела абзацным отступом тоже

\usepackage{multirow} % улучшенное форматирование таблиц
\usepackage{ulem} % подчеркивания
% стиль для для страницы (колонтитулы)
\usepackage{fancyhdr}
%Для списка литературы по ГОСТ
\usepackage[strict]{csquotes}
\makeatletter
\usepackage[english,main=russian]{babel}
\usepackage[square,numbers]{natbib}
%\bibliographystyle{gost2008}
\bibliographystyle{utf8gost705u}
\usepackage{makecell}
\usepackage{amsmath}
\usepackage{amssymb,amsfonts,textcomp}
\usepackage{color}
\usepackage{array}
\usepackage{supertabular}
\usepackage{hhline}
\usepackage{hyperref}
\setlength\tabcolsep{1mm}
\usepackage{tocloft}
\setlength{\cftbeforetoctitleskip}{-15pt}
\usepackage{epstopdf}
\usepackage[space]{grffile} \grffilesetup{encoding,filenameencoding=cp1251}
\usepackage{pdfpages}
\usepackage{xparse}
\usepackage{ifmtarg}% http://ctan.org/pkg/ifmtarg


\begin{document} 

\definecolor{danger}{HTML}{FE996B}
\definecolor{safety}{HTML}{9AFF99}
\definecolor{warning}{HTML}{FFA500}
\newcommand\dangColor[3]{
\FPeval{\tmp}{#1}
\FPeval{\tevdd}{#2+#3}
\FPifgt{\tmp}{#3}{\gdef\era{\cellcolor{warning}}}\else{\gdef\era{\cellcolor{danger}}}\fi
\FPifgt{\tmp}{\tevdd}{\gdef\era{\cellcolor{safety}}}\else{}\fi
\era}
\newcommand\foorows{}

\DeclareDocumentCommand{\addtotable}{m O{---} O{---}O{---}}{%
  \g@addto@macro\foorows{\hline\@gobble}% Insert horizontal rule and gobble first &
  \@for\tmp:=#1\do{%
    \expandafter\g@addto@macro\expandafter\foorows
      \expandafter{\expandafter&\tmp}%  
            }%
\expandafter\g@addto@macro\expandafter\foorows
      \expandafter{\expandafter&#3}
\expandafter\g@addto@macro\expandafter\foorows
      \expandafter{\expandafter&#4}
\expandafter\g@addto@macro\expandafter\foorows
      \expandafter{\expandafter&#2}
\FPeval{\neobhTd}{#2 *0.8}

\IfInteger{#2}{\def\neobhT{\num[round-mode = places, round-precision = 0, round-half = up]{\neobhTd}}}{\def\neobhT{---}}
\newboolean{b3}
\newboolean{b4}
\IfInteger{#3}{\setboolean{b3}{true}}{\setboolean{b3}{false}}
\IfInteger{#4}{\setboolean{b4}{true}}{\setboolean{b4}{false}}
\ifthenelse{\boolean{b3} \AND \boolean{b4}}
{\FPeval{\tevd}{#3+#4}
\def\tev{\num[zero-decimal-to-integer]{\tevd}}
\def\ku{\dangColor{\neobhTd}{#3}{#4}}
}
{
\def\tev{---}
\def\ku{}
}
\expandafter\g@addto@macro\expandafter\foorows
      \expandafter{\expandafter&\ku\neobhT}
            %%
\expandafter\g@addto@macro\expandafter\foorows
      {\expandafter&\ku\tev}
  \g@addto@macro\foorows{\\}%
}
\newcommand\tabKT{
\begin{table}[htb]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
%\mycccc
\rowcolor[HTML]{96FFFB} 
Name 1 &\ Name 2 &\makecell{t1\textsubscript{n}, s} &\makecell{t2\textsubscript{r}, s}&\makecell{t3\textsubscript{b}, s}& \makecell{0,8·t\textsubscript{b}, s}&\makecell{t\textsubscript{e}, s}\\ \hline

\foorows
\hline
\end{tabular}%
}
\caption{My caption}
\label{my-label}
\end{table}
}
\addtotable{name,name}[140][30][120]
\addtotable{name,name}[600][48][400]
\addtotable{name,name}[800][120][200]
\tabKT

\end{document}

enter image description here

enter image description here

3
  • 1
    Could you please make the document complete (with \documentclass, \begin{document}, packages, etc. to make it easier to reproduce the output? Also, could you explain which calculations should be performed on the three cells in each column? And welcome to TeX.SE of course! Commented Feb 12, 2018 at 9:41
  • 1
    It's pretty awful code. If you tell me how to calculate the entries in columns 7 and 8 I can show you a better way to do this. Commented Feb 12, 2018 at 12:00
  • Here content of log file reference: yadi.sk/i/vgnoGKni3SLZGD Commented Feb 13, 2018 at 5:18

1 Answer 1

1

Something like this?

\documentclass{article}
\usepackage{xparse}
\usepackage{siunitx}
\usepackage[table]{xcolor}

\sisetup{
  parse-numbers=true,
  round-precision=4,
  round-mode=figures,
  exponent-product=\ensuremath{{}\cdot{}},
  output-decimal-marker={,}
}


\definecolor{danger}{HTML}{FE996B}
\definecolor{safety}{HTML}{9AFF99}
\definecolor{warning}{HTML}{FFA500}

\ExplSyntaxOn
\NewDocumentCommand{\addtotable}{mmmmm}
 {
  #1 & #2 & #3 & #4 & #5
  & \cellcolor{ \yaroslav_color:nnn { #3 } { #4 } { #5 } } \fp_to_decimal:n { #5 * 0.8 }
  & \cellcolor{ \yaroslav_color:nnn { #3 } { #4 } { #5 } } \fp_to_decimal:n { #3 + #4 }
  \\
  \hline
 }
\cs_new:Nn \yaroslav_color:nnn
 {
  \fp_compare:nTF { #1 + #2 > #3*0.8 } { green } { red }
 }
\ExplSyntaxOff

\begin{document} 

\begin{table}[htb]
\centering

\begin{tabular}{|*{7}{c|}}
\hline
\rowcolor[HTML]{96FFFB}%
Name 1 &\ Name 2 & {$t1_n,s$} & {$t2_r,s$} & {$t3_b,s$} & {$0{,}8\cdot t_b,s$} & {$t_e,s$} \\
\hline
\addtotable{name}{name}{140}{30}{120}
\addtotable{name}{name}{600}{48}{400}
\addtotable{name}{name}{800}{120}{200}
\addtotable{name}{name}{1}{1}{12}
\end{tabular}

\caption{My caption}\label{my-label}

\end{table}

\end{document}

enter image description here

2
  • How to do microbrunch? For diffrent conditions - diffrent clolors? Commented Feb 14, 2018 at 5:49
  • @YaroslavAntropov You can nest conditionals. Commented Feb 14, 2018 at 8:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.