0

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:

  1. 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
  2. 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!

1 Answer 1

1

I had posted this on reddit and got a response linking to gdef. After looking into this I found the edit to this comment was exactly what I was after

1
  • (1) This should better a comment/edit on your question, not an answer because just the link do not show exactly what is your solution. (2) To manage a bulk f variables and data you can consider a mixed solution with knitr (R+LaTeX). There are many examples here and there on this site.
    – Fran
    Jul 11, 2023 at 8:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .