GeneralLabel referring to new environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
MarMel
Posts: 4
Joined: Tue Jan 19, 2010 3:01 pm

Label referring to new environment

Post by MarMel »

Hi,

I just registered and introduced myself in the new members section.. Now, my first real post!

I want to refer to a requirement, which is in the fourth chapter of a report of mine.

I made a new environment called requirement:

Code: Select all

 	\newenvironment{requirement}[2]
	{
	\vspace{1em}
	\noindent \begin{tabular}{r p{8 cm}}
	\textbf{Requirement} \# #1		&	#2 \\
	}
	{
	\end{tabular}
	\vspace{1em}
  	}
Now, I make a requirement like this:

Code: Select all

	\begin{requirement} {\reqnr}
	{The user should be able to program the device accurate to the minute}
	\origin {Some company}
	\rationale {With a more detailed program, energy will be saved}
	\end{requirement}
	
With \reqnr being a counter:

Code: Select all

	\newcounter{requirement-counter}
	\newcommand{\reqnr} {
 		\addtocounter{requirement-counter} {1}
 		\arabic{requirement-counter}
	}
Now, I want to be able to refer to these requirements like "I discussed in requirement 3 blabla".. How can i do this using the \reqnr? I tried using a label, but than it just uses the section number it's in.

Hope you can help!
Thanks

Recommended reading 2024:

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

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

User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Label referring to new environment

Post by Juanjo »

Read this, for example. to know how to step counters in order to capture their value with \label.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
MarMel
Posts: 4
Joined: Tue Jan 19, 2010 3:01 pm

Label referring to new environment

Post by MarMel »

Juanjo wrote:Read this, for example. to know how to step counters in order to capture their value with \label.
Thanks for your reply! Only I still can't make it work.. Lets say I have three requirements (all the other code is same as in my previous post):

Code: Select all

\begin{requirement} {\reqnr}
{The user should be able to program the device accurate to the minute}
\origin {Some company}
\rationale {With a more detailed program, energy will be saved}
\end{requirement}

\begin{requirement} {\reqnr}
{The user should not be confused by the valve-theory}
\origin {Literature}
\rationale {The valve-theory is misleading, so association with it should be avoided}
\end{requirement}

\begin{requirement} {\reqnr}
{The user should be able to alter the desired temperature at any time}
\origin {User observation/interview}
\rationale {Users want to have control and alter the temperature at any time}
\end{requirement}
Now, I want to make this text: "Requirement 1 makes clear that this and that, while requirement 2 says that and this. However, requirement 3 obviously states only that".

Could you give me a hint how to implement this refstepcounter in the example above?
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Label referring to new environment

Post by Juanjo »

You don't provide the definition of \origin and \rationale, so it is not possible to complete your code and compile to see what you expect to get. Anyway, in my opinion, it is simple, in this case, to use a command instead of an environment; likewise, the command \reqnr is superfluous. Try the following example, written, I assume, in the spirit of the code you already provided:

Code: Select all

\documentclass{article}

\newcounter{requirement}
\newcommand{\requirement}[3]%
   {\refstepcounter{requirement}\vspace{0.5em}\par\noindent
    \begin{tabular}{r p{8 cm}}
      \textbf{Requirement \#\therequirement} &   #1 \\
      \textbf{Origin} & #2 \\
      \textbf{Rationale} & #3
    \end{tabular}\vspace{0.5em}}
    
\begin{document}
\requirement%
   {The user should be able to program the device accurate to the minute}
   {Some company}%
   {With a more detailed program, energy will be saved}
\label{one}
\requirement%
   {The user should not be confused by the valve-theory}%
   {Literature}%
   {The valve-theory is misleading, so association with it should be avoided}
\label{two}
\requirement%
   {The user should be able to alter the desired temperature at any time}%
   {User observation/interview}%
   {Users want to have control and alter the temperature at any time}
\label{three}

Requirement \ref{one} makes clear that this and that, 
while requirement \ref{two} says that and this. However, 
requirement \ref{three} obviously states only that

\end{document}
You could also use a list environment (like description), instead of tabular.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
MarMel
Posts: 4
Joined: Tue Jan 19, 2010 3:01 pm

Re: Label referring to new environment

Post by MarMel »

Juanjo: That worked! Thanks! :D
Post Reply