Estou tentando gerar automaticamente uma tabela, que conta suas entradas e fornece rótulos personalizados para cada entrada. Não consigo fazer com que o \customlabel funcione corretamente, ele sempre parece fazer referência à última entrada da lista. Alguém tem uma ideia de como consertar isso?
Obrigado!
Arquivo CLS:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myCLS}[bla]
\LoadClass[12pt]{article}
% requirements
\newcounter{NameOfTheNewCounter}
\setcounter{NameOfTheNewCounter}{0}
\newcommand\themissionreqnumber{%
\ifnum\value{NameOfTheNewCounter}<100 0\fi
\protect\arabic{NameOfTheNewCounter}}
\newcommand{\missionrequiremententries}{}
\newcommand{\missionrequirement}[3]{%
\protected@xdef\missionrequiremententries{\missionrequiremententries \protect\addtocounter{NameOfTheNewCounter}{10}MIS-\protect\themissionreqnumber & #2 & #3 \protect\\}\protect\customlabel{#1}{MIS-\protect\themissionreqnumber}}
\RequirePackage[a4paper,%
top=3.28cm, bottom=3.10cm,%
left=2.0cm, right=1.95cm,%
headsep=0.2cm,headheight=50pt,heightrounded,%
footskip=1.3cm]{geometry}% Change the page dimensions and margins
\RequirePackage[table]{xcolor}% Colours
\definecolor{lightgrey}{RGB}{230,230,230}
\RequirePackage{tabularx,booktabs,colortbl}% Improved tables
e arquivo .tex principal (compilado usando XeLaTex)
\documentclass{myCLS}
\usepackage[hidelinks]{hyperref}
\makeatletter
\newcommand{\customlabel}[2]{%
\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{\thepage}{#2}{#1}{}} }%
}
\makeatother
\newcommand{\missionrequirementstable}{%
\noindent
\begin{table}[h]
\caption{Requirements}\label{tab:req}
{\footnotesize
\begin{tabularx}{\columnwidth}{p{2cm}|X|p{2cm}}
\hline
\rowcolor{lightgrey}{\bfseries ID} & {\bfseries Statement} & {\bfseries Parent ID}\\
\hline
\missionrequiremententries
\hline
\end{tabularx}
}
\end{table}
}
\begin{document}
\missionrequirement{myFirstLabel}{My text.}{\ref{mySecondLabel}}
\missionrequirement{mySecondLabel}{My new text.}{\ref{myFirstLabel}}
\missionrequirementstable
\ref{myFirstLabel}
\end{document}
Responder1
Ei, resolvi esse problema. Parecia estar na cláusula if
Código errado:
\newcommand\themissionreqnumber{%
\ifnum\value{NameOfTheNewCounter}<100 0\fi
\protect\arabic{NameOfTheNewCounter}}
correção (na verdade não testada, mas esse também foi o erro nas minhas primeiras tentativas do novo código, veja o código de trabalho abaixo)
\newcommand\themissionreqnumber{%
{\ifnum\value{NameOfTheNewCounter}<100 0\fi}
\protect\arabic{NameOfTheNewCounter}}
Mas eu codifiquei de uma maneira completamente diferente agora:
\newcounter{NameOfTheNewCounter}
\renewcommand{\theNameOfTheNewCounter}{MIS-{\ifnum\value{NameOfTheNewCounter}<100 0\fi}\arabic{misreqs}}
\newcommand{\NameOfTheNewCounterCnt}[1]{%
\addtocounter{NameOfTheNewCounter}{10}% Step counter
\theNameOfTheNewCounter% Print counter
\addtocounter{NameOfTheNewCounter}{-1}\refstepcounter{NameOfTheNewCounter}\label{#1}}% Mark with label
\newcommand{\missionrequiremententries}{}
\newcommand{\missionrequirement}[3]{%
\protected@xdef\missionrequiremententries{\missionrequiremententries \protect\misreqCnt{#1} & #2 & #3 \protect\\}}
{\footnotesize
\begin{longtable}{p{1.7cm}|p{11.9cm}|p{2cm}}
\caption{Mission Requirements}\label{tab:mission_req}\\
\hline
\rowcolor{lightgrey}{\bfseries Req. ID} & {\bfseries Statement} & {\bfseries Parent ID}\\
\hline
\endhead
\missionrequiremententries
\hline
\end{longtable}}}
\begin{document}
\missionrequirement{myFirstLabel}{My text.}{\ref{mySecondLabel}}
\missionrequirement{mySecondLabel}{My new text.}{\ref{myFirstLabel}}
\missionrequirementstable
\ref{myFirstLabel}
\end{document}