General ⇒ \label question for experts
\label question for experts
Hello,
I am using a newcommand with 2 arguments which basically sets a couple of minipages and an \item. It works perfectly, see below:
\newcommand{\entryNN}[2]{
\addtocounter{pippo}{1}
\begin{minipage}[t]{.25\textwidth}
\noindent \small \bfseries \sffamily \raggedleft{#1}
\end{minipage}
\begin{minipage}[t]{.7\textwidth}
\begin{list}{\arabic{pippo}.}{\topsep -0cm \leftmargin .6cm \itemsep 0cm
\parsep 0.05cm}
\item #2
\end{list}
\end{minipage}\vspace{.2cm}
}
Now I would like to place a \label{} associated to this newcommand, to dinamically reference it through a \ref{} command. So I modified the newcommand, adding a futher argument (the \label argument) as follows:
\newcommand{\entryNN}[3]{
\addtocounter{pippo}{1}
\begin{minipage}[t]{.25\textwidth}
\noindent \small \bfseries \sffamily \raggedleft{#2}
\end{minipage}
\begin{minipage}[t]{.7\textwidth}
\begin{list}{\arabic{pippo}.}{\topsep -0cm \leftmargin .6cm \itemsep 0cm
\parsep 0.05cm}
\label{#1}
\item #3
\end{list}
\end{minipage}\vspace{.2cm}
}
I basically added a futher argument in \entryNN{}{}{} and a \label{#1} with that argument, which is supposed to create a label in the \beginin{list} environment.
Unfortunately it does not work. Where am I wrong?
Thanks,
Gyru
I am using a newcommand with 2 arguments which basically sets a couple of minipages and an \item. It works perfectly, see below:
\newcommand{\entryNN}[2]{
\addtocounter{pippo}{1}
\begin{minipage}[t]{.25\textwidth}
\noindent \small \bfseries \sffamily \raggedleft{#1}
\end{minipage}
\begin{minipage}[t]{.7\textwidth}
\begin{list}{\arabic{pippo}.}{\topsep -0cm \leftmargin .6cm \itemsep 0cm
\parsep 0.05cm}
\item #2
\end{list}
\end{minipage}\vspace{.2cm}
}
Now I would like to place a \label{} associated to this newcommand, to dinamically reference it through a \ref{} command. So I modified the newcommand, adding a futher argument (the \label argument) as follows:
\newcommand{\entryNN}[3]{
\addtocounter{pippo}{1}
\begin{minipage}[t]{.25\textwidth}
\noindent \small \bfseries \sffamily \raggedleft{#2}
\end{minipage}
\begin{minipage}[t]{.7\textwidth}
\begin{list}{\arabic{pippo}.}{\topsep -0cm \leftmargin .6cm \itemsep 0cm
\parsep 0.05cm}
\label{#1}
\item #3
\end{list}
\end{minipage}\vspace{.2cm}
}
I basically added a futher argument in \entryNN{}{}{} and a \label{#1} with that argument, which is supposed to create a label in the \beginin{list} environment.
Unfortunately it does not work. Where am I wrong?
Thanks,
Gyru
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
\label question for experts
Hi Gyru,
welcome to this forum!
Just a general information: if you provide a minimal working example it would be easier to help. Not everybody will take time to complete your code fragments to get a compilable document for testing if you don't give compilable code.
Stefan
welcome to this forum!
Just a general information: if you provide a minimal working example it would be easier to help. Not everybody will take time to complete your code fragments to get a compilable document for testing if you don't give compilable code.
Stefan
LaTeX.org admin
Re: \label question for experts
I haven't tried to understand your code, but anyway I can point out a couple of things. Presumably you want to reference each instance of \entryNN through the value of the pippo counter, that is, you expect that the \label commands catches the last value of pippo. If so, replace \addtocounter{pippo}{1} by \refstepcounter{pippo} and put the \label command right after it. Note that there are three different commands to increase counters: \addtocounter, \stepcounter and \refstepcounter. Each one has a different secondary effect. The \label command picks only the value of the last counter whose value has been increased by one with \refstepcounter.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Re: \label question for experts
@ Juanjo: That's *EXACTLY* what I needed and it works perfectly! THANK YOU!!
There is only a minor drawback: if I leave the label key empty in the \entryNN{} the compilers thinks that there are multiple EMTPY labels ('') and gives lot of warnings (I use an long list of \entryNN. Is there a way to tell him not to bother in case of empty labels?
@Stefan_K: sorry for not providing a minimal working code
There is only a minor drawback: if I leave the label key empty in the \entryNN{} the compilers thinks that there are multiple EMTPY labels ('') and gives lot of warnings (I use an long list of \entryNN. Is there a way to tell him not to bother in case of empty labels?
@Stefan_K: sorry for not providing a minimal working code
\label question for experts
You can check if the corresponding argument is empty and so skip the \label command. Or you can automatically generate a label (say, for example, entry1, entry2, etc.); hence the first argument of \entryNN will not be longer needed and there will be no empty labels. For a more detailed advice, you should say which solution fits your needs and provide a minimal working example showing the use of \entryNN and some references to it.here is only a minor drawback: if I leave the label key empty in the \entryNN{} the compilers thinks that there are multiple EMTPY labels ('') and gives lot of warnings (I use an long list of \entryNN. Is there a way to tell him not to bother in case of empty labels?
Edited to complete below the answer:
Once reconsidered the problem, I find better the first solution. Here is a suitable code to be put in the preamble:
Code: Select all
\newcounter{pippo}
\makeatletter
\newcommand{\entryNN}[3]{%
\refstepcounter{pippo}\def\@temp{#1}%
\ifx\@temp\@empty\relax\else\label{#1}\fi
\begin{minipage}[t]{0.25\textwidth}
\small\bfseries\sffamily\raggedleft #2
\end{minipage}\hfill
\begin{minipage}[t]{0.7\textwidth}
\begin{list}{\arabic{pippo}.}%
{\setlength{\topsep}{0cm}\setlength{\partopsep}{0cm}
\setlength{\itemsep}{0cm}\setlength{\parsep}{0.05cm}
\setlength{\leftmargin}{0.6cm}}
\item #3
\end{list}
\end{minipage}
\vspace{0.2cm}}
\makeatother
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Re: \label question for experts
Thanks again for your efforts. With your suggestion the code is still doing the right things and the minor improvements are working perfectly.
Unfortunately during the compilation I still get the <<label '' multiply defined>> warning...
gyru
Unfortunately during the compilation I still get the <<label '' multiply defined>> warning...
gyru
\label question for experts
I haven't those warnings. To discover their cause, it is necessary to see a minimal working example.gyru73 wrote: Unfortunately during the compilation I still get the <<label '' multiply defined>> warning...
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Re: \label question for experts
Ok, it was my trivial mistake, now EVERYTHING works perfectly! Thanks a lot for the great suggestions!
T
T