GeneralBuilding a table based upon sections or labels

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
bakuretsu
Posts: 1
Joined: Wed May 19, 2010 5:33 pm

Building a table based upon sections or labels

Post by bakuretsu »

Hi everyone! This is my first post on the LaTeX Community forum. I just first want to say that this forum has been an invaluable reference as I have begun learning more and more about LaTeX, which is rather undocumented in some areas.

Here is what I want to do. I have built up my own style set for a "requirements document" that I use as a basic template here at work. The purpose of the document is to collect the requirements for a project.

I created an environment that automatically generates requirement numbers and uses tabularx to output a pretty table. Basically what you get is like this:

R001 This is the description of the requirement
R002 This is the description of the second requirement

The R001 and R002 parts are counter values output with \padzeroes from the fmtcount package.

The main content of the document, though, is a series of descriptions for each of the requirements, something like:

Code: Select all

\subsection{R001 - This is the description of the requirement}
\begin{itemize}
  \item A specific requirement
  \item Another specific requirement
\end{itemize}
If I ever add or change the main list, however, I have to go through and manually change the section titles because the numbers will be off.

What I would ideally like to do is just write all of the detailed requirements out using some predefined labeling scheme, and have LaTeX generate the TABLE for me (the one that I created the environment for). The issue is that I have absolutely no idea how to make a command that can "look ahead" through the document for certain data and parse it.

This would work sort of like the table of contents does.

Is this even possible? Am I getting in way over my head?

I should mention that I am a programmer by trade, and although a lot of LaTeX's internals are cryptic to me, the programming concepts required to make this work seem relatively straightfoward, so feel free to give me just a direction to go in or some documents to read and I'll figure it out!

Thanks in advance!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

barcense
Posts: 10
Joined: Sun Jun 10, 2007 2:16 pm

Building a table based upon sections or labels

Post by barcense »

As a first idea, you can use something like:

Code: Select all

\documentclass{article}
\usepackage{fmtcount}
\usepackage{tocloft}

\newcommand{\listrequirement}{Requirements}
\newlistof{requirement}{req}{\listrequirement}
\renewcommand{\therequirement}{R\hspace{-3pt}\padzeroes[3]\decimal{requirement}}
\renewcommand{\cftrequirementdotsep}{\cftnodots}
\renewcommand{\cftreqtitlefont}{\large\bfseries}
\cftpagenumbersoff{requirement}
\newenvironment{requirement}[1]{\addtocounter{requirement}{1}%
\addcontentsline{req}{requirement}{\protect\numberline{\therequirement}\ --\ #1}\par%
\addcontentsline{toc}{subsection}{\protect\numberline{Requirement\ \therequirement}}%
\noindent \therequirement\ --\ #1 \begin{itemize}}{\end{itemize}}

\begin{document}
\tableofcontents
\listofrequirement
\bigskip
\section{one}
\begin{requirement}{This is the description of the first requirement}
 \item A specific requirement
 \item Another specific requirement
\end{requirement}
\section{two}
\begin{requirement}{This is the description of the second requirement}
 \item A specific requirement
 \item Another specific requirement
\end{requirement}
\end{document}
Post Reply