1

I'm working on macros to format time estimates to execute project tasks. I have a custom environment to format subtask estimates and now I want to add a table summarizing everything.

I'm using tocloft to create a custom list and it works as expected for all the subtask entries but I would also like to show the summary for the full milestone. What I have right now gets all the content right but the milestone summery in the list of estimates is after the subtasks whereas I want it before. If I put the respective macro at the start of the section placement in the list of estimates is correct but estimate itself it incorrect (0 days).

How can I either get the the milestone line before the subtasks but also have the correct estimate?

enter image description here

\documentclass[11pt,letterpaper,oneside]{article}
\usepackage{tocloft}

%---------------------------------------------------------------------- % Environment for estimates %---------------------------------------------------------------------- \newcommand{\listestimatename}{List of Estimates} \newlistof{estimate}{est}{\listestimatename} \newlistentry{subestimate}{est}{1} \setcounter{estdepth}{2}

\cftsetindents{estimate}{1em}{1.5em} \cftsetindents{subestimate}{2em}{3.8em}

\newcommand{\CurWorkLabel}{}

\newcounter{cntScnWorkEstimate}[section] \newcounter{cntEnvWorkEstimate}

\newenvironment{workestimate}[1] { \small \renewcommand{\CurWorkLabel}{#1} \setcounter{cntEnvWorkEstimate}{0} \begin{tabular}{c l} \multicolumn{2}{l}{\emph{#1}}\tabularnewline \hline } { % finish the table \textbf{\emph{\thecntEnvWorkEstimate\ days}} & \textbf{\emph{Total}} \end{tabular}

% now add a list of estimates entry \phantomsection \addcontentsline{est}{subestimate} {\protect\numberline{\thesubsection}\CurWorkLabel\ (\thecntEnvWorkEstimate\ days)} }

\newcommand{\estimate}[2]{% \addtocounter{cntEnvWorkEstimate}{#1}% \addtocounter{cntScnWorkEstimate}{#1}% \emph{#1 days} & #2 \tabularnewline }

\newcommand{\addsectionestimate}[1]{% \addcontentsline{est}{estimate} {\protect\numberline{\thesection}\textbf{#1 Total} (\thecntScnWorkEstimate\ days)} }

%---------------------------------------------------------------------- % Now the actual document %---------------------------------------------------------------------- \begin{document} \listofestimate

\section{Milestone 1} \subsection{Sub Task 1} \begin{workestimate}{Subtask1 Estimate} \estimate{1}{detail A} \estimate{2}{detail B} \end{workestimate}

Long description of how this sub task will be carried out.

\subsection{Sub Task 2} \begin{workestimate}{Subtask 2 Estimate} \estimate{3}{detail C} \estimate{4}{detail D} \end{workestimate}

Long description of how this sub task will be carried out.

\addsectionestimate{Milestone 1}

\end{document}

ryan0270
  • 235
  • Just for my understanding: why don't you use project management (PM) software for this purpose? There are also open source PM's available ... – MS-SPO Aug 04 '21 at 15:55

2 Answers2

1

Your main issue here is that you want to refer to something prior to it being printed/displayed. The most convenient way of doing this is via the \label-\ref system (through the .aux file). The following code implements that via a milestone environment, setting a sequential \label at the end that captures the sum of your day counters.

enter image description here

\documentclass{article}

\usepackage{tocloft}

%---------------------------------------------------------------------- % Environment for estimates %---------------------------------------------------------------------- \newcommand{\listestimatename}{List of Estimates} \newlistof{estimate}{est}{\listestimatename} \newlistentry{subestimate}{est}{1} \setcounter{estdepth}{2}

\cftsetindents{estimate}{1em}{1.5em} \cftsetindents{subestimate}{2em}{3.8em}

\newcommand{\CurWorkLabel}{}

\newcounter{cntScnWorkEstimate}[section] \newcounter{cntEnvWorkEstimate}

\newenvironment{workestimate}[1]{% \small \renewcommand{\CurWorkLabel}{#1}% \setcounter{cntEnvWorkEstimate}{0}% \begin{tabular}{c l} \multicolumn{2}{l}{\emph{#1}}\tabularnewline \hline }{% % finish the table \textbf{\emph{\thecntEnvWorkEstimate\ days}} & \textbf{\emph{Total}} \end{tabular}

% now add a list of estimates entry \phantomsection \addcontentsline{est}{subestimate} {\protect\numberline{\thesubsection}\CurWorkLabel\ (\thecntEnvWorkEstimate\ days)} }

\newcommand{\estimate}[2]{% \addtocounter{cntEnvWorkEstimate}{#1}% \addtocounter{cntScnWorkEstimate}{#1}% \emph{#1 days} & #2 \tabularnewline }

\newcommand{\subtask}{\subsection}

\newcounter{milestone} \makeatletter \newenvironment{milestone}[1]{% \section{#1}% \stepcounter{milestone}% \addcontentsline{est}{estimate} {\protect\numberline{\thesection}\textbf{#1 Total} (\ref{milestone-\themilestone}~days)}% }{% \edef@currentlabel{\thecntScnWorkEstimate}% \label{milestone-\themilestone}% } \makeatother

%---------------------------------------------------------------------- % Now the actual document %---------------------------------------------------------------------- \begin{document} \listofestimate

\begin{milestone}{Milestone 1}

\subtask{Sub Task 1} \begin{workestimate}{Subtask 1 Estimate} \estimate{1}{detail A} \estimate{2}{detail B} \end{workestimate}

Long description of how this sub task will be carried out.

\subtask{Sub Task 2} \begin{workestimate}{Subtask 2 Estimate} \estimate{3}{detail C} \estimate{4}{detail D} \end{workestimate}

Long description of how this sub task will be carried out.

\end{milestone}

\end{document}

Upon first compile the \label is written to the .aux. The second compilation picks up the appropriate value via \ref and writes it to the .est (equivalent to a .toc). The third compilation now correctly picks up the \ref and displays it in the List of Estimates.

You don't need to compile 3 times every time you want to view the output... only when there's a change in the content of a milestone's elements, or the \estimates.

Werner
  • 603,163
0

At least a partial solution: move up \addsectionestimate{Milestone 1} before \listofestimate . This will put it into the right place. You probably need to adjust the counter in your \newcommand{\addsectionestimate} .

Screenshot:

enter image description here

Modified code:

\documentclass[11pt,letterpaper,oneside]{article}
\usepackage{tocloft}

%---------------------------------------------------------------------- % Environment for estimates %---------------------------------------------------------------------- \newcommand{\listestimatename}{List of Estimates} \newlistof{estimate}{est}{\listestimatename} \newlistentry{subestimate}{est}{1} \setcounter{estdepth}{2}

\cftsetindents{estimate}{1em}{1.5em} \cftsetindents{subestimate}{2em}{3.8em}

\newcommand{\CurWorkLabel}{}

\newcounter{cntScnWorkEstimate}[section] \newcounter{cntEnvWorkEstimate}

\newenvironment{workestimate}[1] { \small \renewcommand{\CurWorkLabel}{#1} \setcounter{cntEnvWorkEstimate}{0} \begin{tabular}{c l} \multicolumn{2}{l}{\emph{#1}}\tabularnewline \hline } { % finish the table \textbf{\emph{\thecntEnvWorkEstimate\ days}} & \textbf{\emph{Total}} \end{tabular}

% now add a list of estimates entry \phantomsection \addcontentsline{est}{subestimate} {\protect\numberline{\thesubsection}\CurWorkLabel\ (\thecntEnvWorkEstimate\ days)} }

\newcommand{\estimate}[2]{% \addtocounter{cntEnvWorkEstimate}{#1}% \addtocounter{cntScnWorkEstimate}{#1}% \emph{#1 days} & #2 \tabularnewline }

% probably need to adjust counter here \newcommand{\addsectionestimate}[1]{% \addcontentsline{est}{estimate} {\protect\numberline{\thesection}\textbf{#1 Total} (\thecntScnWorkEstimate\ days)} }

%---------------------------------------------------------------------- % Now the actual document %---------------------------------------------------------------------- \begin{document}

\addsectionestimate{Milestone 1}% <<== \listofestimate

\section{Milestone 1} \subsection{Sub Task 1} \begin{workestimate}{Subtask1 Estimate} \estimate{1}{detail A} \estimate{2}{detail B} \end{workestimate}

Long description of how this sub task will be carried out.

\subsection{Sub Task 2} \begin{workestimate}{Subtask 2 Estimate} \estimate{3}{detail C} \estimate{4}{detail D} \end{workestimate}

Long description of how this sub task will be carried out.

\end{document}

Further suggestions due to the originators comment: Ok, I start to see your problem. Besides the correct numbering of sections and subsections you also want to have the various counting results. Let's have a look, step by step.

I suggest to disentangle the estimate-command:

\newcommand{\estimate}[2]{%
  \addtocounter{cntEnvWorkEstimate}{#1}%
  \addtocounter{cntScnWorkEstimate}{#1}%
     \emph{#1 days} & #2 \tabularnewline%<<==
}

If you would suppress the printout \emph{#1 days} & #2 \tabularnewline, then you could put the reduced estimate-commands first, to do the calculations. You omit all section-commands here.

Assuming you can read out the counting results and store them somewhere, in a second step you could build your documents structure AND just read out the previously stored counting results ... so you can create titles e.g. with the number of days included.

To emphasize, the idea is to separate in code: count first, store, print later.

So all that's left to do is to find a storage solution.

If you have a fixed number of sections, then all you need to do is to define enough new counts, for example, which you preset after running your estimates ... with the estimates calculated.

If it's more dynamic, either find a dynamic storage and retrieval OR make it more static.

So basically your codes structure would be sth. like this:

% ...
\newcommand{\estimate}[1]{%
  \addtocounter{cntEnvWorkEstimate}{#1}%
  \addtocounter{cntScnWorkEstimate}{#1}%
}
  \begin{document}   
% ...
    \begin{workestimate}{Subtask1 Estimate}
        \estimate{1}{detail A}
        \estimate{2}{detail B}
    \end{workestimate}

% store result % next workestimate environment % ...

\tableofcontents % instead of \listofestimate \section{Milestone 1 \theCalculated days}% idea is to literally write the title \subsection{Sub Task 1 \theOtherCalculated days} % some output as in the deleted \emph{} part % ... \end{document}

Hope this helps.

If it doesn't you'd need to take advantage of the required, at least, double compile run, i.e. access and process the information stored in .toc, .aux etc.

So I suggest trying hard to make separate in code work ;-)

MS-SPO
  • 11,519
  • Yeah, I know I can put \addsectionestimate earlier to get it in the correct place but I can't figure out how to adjust the counter so it displays the correct value – ryan0270 Aug 04 '21 at 17:26
  • Try: https://tex.stackexchange.com/search?q=adjusting+counter – MS-SPO Aug 04 '21 at 17:41
  • Sorry, I'm not seeing how that works for my use case. From my (limited) understanding, the counter has to be adjusted before \addsectionestimate but I don't know the correct counter value until the end of the section – ryan0270 Aug 04 '21 at 19:12
  • @ryan0270, Please see Further suggestions due to the originators comment in my answer. – MS-SPO Aug 04 '21 at 22:11