1
\documentclass{article}
\usepackage{xfp}
\usepackage[english]{babel}
%\usepackage{siunitx}
\usepackage{booktabs,multicol,multirow}
\makeatletter
\def\avgthree#1#2#3{\fpeval{(#1+#2+#3)/3}}
\def\valagre#1#2#3{\fpeval{(#1*#2)+#3}}
\makeatother

\newcommand{\tiempo}{2}\newcommand{\tr}{6}\newcommand{\costo}{2}
\newcommand{\tiempotwo}{3}\newcommand{\trtwo}{5}\newcommand{\costotwo}{4}
\newcommand{\tiempothree}{2.5}\newcommand{\trthree}{4}\newcommand{\costothree}{1.98}
\newcommand{\benifCEE}{0.26}

\newcommand{\pesoone}{\fpeval{round(\avgthree{(\tiempo)}{(\tr)}{(\costo)},2)}}
\newcommand{\pesotwo}{\fpeval{round(\avgthree{(\tiempotwo)}{(\trtwo)}{(\costotwo)},2)}}
\newcommand{\pesothree}{\fpeval{round(\avgthree{(\tiempothree)}{(\trthree)}{(\costothree)},2)}}
\newcommand{\vaone}{\fpeval{round(\valagre{(\pesoone)}{(\benifCEE)}{(\costo)},2)}}
\newcommand{\vatwo}{\fpeval{round(\valagretwo{(\pesotwo)}{(\benifCEE)}{(\costotwo)},2)}}
\newcommand{\vathree}{\fpeval{round(\valagrethree{(\pesothree)}{(\benifCEE)}{(\costothree)},2)}}
\begin{document}
In table \ref{added value process} it shows
\begin{table}[!h]
    \begin{tabular}{|l|c|c|c|c|c|c|}\midrule
        Proceso&tiempo&T\_retraso&costo&peso&beneficio&VAgre\\\midrule
        Abastec.& \tiempo\ & \tr\ & \costo\ & \pesoone\  &\benifCEE & \vaone\\\midrule
        Prep.   & \tiempotwo & \trtwo & \costotwo & \pesotwo & \benifCEE & \vatwo \\\midrule
        Calibr. & \tiempothree\ & \trthree\ & \costothree\ & \pesothree\  &\benifCEE & \vathree\\\midrule
    \end{tabular}\\
    \caption{Added value of process}
\label{added value process}
\end{table}
\end{document}

This .tex file print the table but give error. Can anybody help me with that.

4
  • line 33: Undefined control sequence. ... \costotwo & \pesotwo & \benifCEE & \vatwo line 34: Undefined control sequence. ...hree\ & \pesothree\ &\benifCEE & \vathree line 30: Underfull \hbox (badness 10000) in paragraph Apr 6, 2018 at 13:22
  • The full error message fully state that \valagretwo is not defined. And it isn't
    – daleif
    Apr 6, 2018 at 13:49
  • I want create a table with numeric variable to make some calculation. the column 1, 2 and 3 are the necessary data and column 4 make a calculation using column1,2 and 3. Column 6 make a calculation using column3,4 and 5. The variable vatwo and vathree give the errors previously commented. Apr 6, 2018 at 13:59
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Jul 5, 2018 at 19:43

3 Answers 3

2

I think you're better served with a single macro for each row:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}

\usepackage{xfp}
\usepackage{siunitx}
\usepackage{booktabs}

\newcommand{\proceso}[5]{%
  #1 & % description
  #2 & % time
  #3 & % cost
  #4 & % delay
  \fpeval{round((#2+#3+#4)/3,2)} & % weight
  #5 & % benefit
  \fpeval{round((#2+#3+#4)*#5/3+#4,2)}
}

\begin{document}

\begin{tabular}{l*{6}{S[table-format=1.2]}}
\toprule
Proceso & {tiempo} & {T\_retraso} & {costo} & {peso} & {beneficio} & {VAgre} \\
\midrule
\proceso{Abastec.}{2}  {6}{2}   {0.26} \\
\proceso{Prep.}   {3}  {5}{4}   {0.26} \\
\proceso{Calibr.} {2.5}{4}{1.98}{0.26} \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

1

Changing \valagretwo and \valagrethree by \valagre.

\documentclass{article}
\usepackage{xfp}
\usepackage[english]{babel}
%\usepackage{siunitx}
\usepackage{booktabs,multicol,multirow}
\makeatletter
\def\avgthree#1#2#3{\fpeval{(#1+#2+#3)/3}}
\def\valagre#1#2#3{\fpeval{(#1*#2)+#3}}
\makeatother

\newcommand{\tiempo}{2}\newcommand{\tr}{6}\newcommand{\costo}{2}
\newcommand{\tiempotwo}{3}\newcommand{\trtwo}{5}\newcommand{\costotwo}{4}
\newcommand{\tiempothree}{2.5}\newcommand{\trthree}{4}\newcommand{\costothree}{1.98}
\newcommand{\benifCEE}{0.26}

\newcommand{\pesoone}{\fpeval{round(\avgthree{(\tiempo)}{(\tr)}{(\costo)},2)}}
\newcommand{\pesotwo}{\fpeval{round(\avgthree{(\tiempotwo)}{(\trtwo)}{(\costotwo)},2)}}
\newcommand{\pesothree}{\fpeval{round(\avgthree{(\tiempothree)}{(\trthree)}{(\costothree)},2)}}
\newcommand{\vaone}{\fpeval{round(\valagre{(\pesoone)}{(\benifCEE)}{(\costo)},2)}}
\newcommand{\vatwo}{\fpeval{round(\valagre{(\pesotwo)}{(\benifCEE)}{(\costotwo)},2)}}
\newcommand{\vathree}{\fpeval{round(\valagre{(\pesothree)}{(\benifCEE)}{(\costothree)},2)}}
\begin{document}
In table \ref{added value process} it shows
\begin{table}[!h]
    \begin{tabular}{|l|c|c|c|c|c|c|}\midrule
        Proceso&tiempo&T\_retraso&costo&peso&beneficio&VAgre\\\midrule
        Abastec.& \tiempo\ & \tr\ & \costo\ & \pesoone\  &\benifCEE & \vaone\\\midrule
        Prep.   & \tiempotwo & \trtwo & \costotwo & \pesotwo & \benifCEE & \vatwo \\\midrule
        Calibr. & \tiempothree\ & \trthree\ & \costothree\ & \pesothree\  &\benifCEE & \vathree\\\midrule
    \end{tabular}\\
    \caption{Added value of process}
\label{added value process}
\end{table}
\end{document}
1

In case you might be interested in a different approach, here is one with pgfplotstable. This avoids having to define so many new macros.

enter image description here

\documentclass{article}
\usepackage{pgfplotstable} % added
\usepackage{xfp}
\usepackage[english]{babel}
%\usepackage{siunitx}
\usepackage{booktabs}

% don't need \makeatletter (no @), and \newcommand is recommended
\newcommand\avgthree[3]{\fpeval{(#1+#2+#3)/3}}
\newcommand\valagre[3]{\fpeval{(#1*#2)+#3}}


\pgfplotstableread{
Proceso  tiempo Tr costo beneficio
Abastec. 2 6 2 0.26
Prep. 3 5 4 0.26
Calibr. 2.5 4 1.98 0.26
}\datatab

% create peso column
\pgfplotstablecreatecol[
  create col/assign/.code={
    \edef\entry{\avgthree{\thisrow{tiempo}}{\thisrow{Tr}}{\thisrow{costo}}}
    \pgfkeyslet{/pgfplots/table/create col/next content}\entry
  }]{peso}\datatab

% create VAgre column
\pgfplotstablecreatecol[
  create col/assign/.code={
    \edef\entry{\valagre{\thisrow{peso}}{\thisrow{beneficio}}{\thisrow{costo}}}
    \pgfkeyslet{/pgfplots/table/create col/next content}\entry
  }]{VAgre}\datatab

\begin{document}


In table \ref{added value process} it shows
\begin{table}
\centering

\pgfplotstabletypeset[
 % set column order
 columns={Proceso,tiempo,Tr,costo,peso,beneficio,VAgre},
 columns/Proceso/.style={
   string type, % don't parse as numbers
   column type=l % set alignment
 },
 columns/Tr/.style={
   column name={T\_retraso} % change displayer column name from Tr
 },
 every head row/.style={
  before row={\toprule},
  after row={\midrule}
 },
 every last row/.style={
  after row=\bottomrule
 }
]\datatab

\caption{Added value of process}
\label{added value process}
\end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.