General ⇒ \label question for experts
\label question for experts
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
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
\label question for experts
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
Re: \label question for experts
Re: \label question for experts
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
Re: \label question for experts
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...
Re: \label question for experts
T