I am writing a document that involves a table of information for many sections, something like:
\textbf{Details:}
\begin{table}[H]
\begin{center}
\begin{tabularx}{\linewidth}{|X|c|c|c|c|c|}
\hline
\textbf{Number} & \textbf{Location} & \textbf{Duration (hr)} & \textbf{Labour (\$)} & \textbf{Equipment Hire/Purchase (\$)} & \textbf{Consumables (\$)} & \textbf{Total (\$)}\\
\hline
1 & In-house & 0.5 & 39 & 0 & 0 & 39\\
2 & Out-house1 & 1 & 78 & 1000 & 500 & 1578\\
3 & Out-house2 & 1.5 & 78 & 800 & 700 & 1617\\
\hline
\end{tabularx}
\end{center}
\end{table}
However, the data in the table needs to be summarized later for about 50 of these small tables, only to include the 'Location' 'Duration (hr)' and 'Total ($)' columns.
I have two requirements:
- set the entries in the table as a variable that can be called on later, so I only need to enter the values in the individual tables once which then automatically get updated in the summary
- the entries should be math operable (ie I should be able to only need to enter the first 4 numerical values and the total should be automatically calculated
My idea was something along the lines of:
\textbf{Details:}
\begin{table}[H]
\begin{center}
\begin{tabularx}{\linewidth}{|X|c|c|c|c|c|c|}
\hline
\textbf{Number} & \textbf{Location} & \textbf{Duration (hr)} & \textbf{Labour (\$)} & \textbf{Equipment Hire/Purchase (\$)} & \textbf{Consumables (\$)} & \textbf{Total (\$)}\\
\hline
\entry{1}{1}{1} & \entry{1}{2}{In-house} & \entry{1}{3}{0.5} & \entry{1}{4}{\entry{1}{3} * 78} & \entry{1}{5}{0} & \entry{1}{6}{0} & \entry{1}{7}{\entry1{4} + \entry{1}{5} + \entry1{6}}\\
% etc
\hline
\end{tabularx}
\end{center}
\end{table}
Which I can later use in a different table like this:
\textbf{Summary:}
\begin{table}[H]
\begin{center}
\begin{tabularx}{\linewidth}{|X|c|c|c|}
\hline
\textbf{Number} & \textbf{Location} & \textbf{Cost (\$)} & \textbf{Duration (Hr)}\\
\hline
\entry{1}{1} & \entry{1}{2} & \entry{1}{7} & \entry{1}{3}\\
\entry{2}{1} & \entry{2}{2} & \entry{2}{7} & \entry{2}{3}\\
\entry{3}{1} & \entry{3}{2} & \entry{3}{7} & \entry{3}{3}\\
\entry{4}{1} & \entry{4}{2} & \entry{4}{7} & \entry{4}{3}\\
% etc
\mulitcolumn{2}{r|}{Total} & sum(\entry{all}{7}) & sum(\entry{all}{3})\\
\hline
\end{tabularx}
\end{center}
\end{table}
I Have tried
\newcommand{\name}[1]{\def\showname{#1}}
which only worked if the \showname was called within the same table but not in a different one (despite the \newcommand being in the pre-amble)
Any help is appreciated and thank you for your help!
knitr(R+LaTeX). There are many examples here and there on this site. – Fran Jul 11 '23 at 08:51