
Quero numerar as linhas de uma tabela com algarismos romanos e, quando fizer referência cruzada, a referência será impressa da mesma maneira.
Por exemplo,
\documentclass{article}
\begin{document}
\newcounter{foo}
\newcommand{\rfoo}{\refstepcounter{foo}(\roman{foo})}
\begin{tabular}{r|l}
\hline
\rfoo\label{f1} & First line \\ \hline
\rfoo\label{f2} & Second line \\ \hline
\hline
\end{tabular}
\
The first line is \ref{f1}. The second line is \ref{f2}.
\end{document}
dá
Mas o que eu quero é:
Responder1
Cada contador tem uma macro chamada \the...
, digamos que o contador foo
terá \thefoo
. Esta \the...
macro faz por padrão a saída do valor do contador com números arábicos.
\thefoo
é usado também para o rótulo conforme ele é gravado no .aux
arquivo. Se format (i)
, for solicitado, ele deverá ser escrito no .aux
arquivo e usado em \thefoo
.
Então
\renewcommand{\thefoo}{(\roman{foo})}
é o nome do jogo ;-)
\documentclass{article}
\newcounter{foo}
\renewcommand{\thefoo}{(\roman{foo})}
\newcommand{\rfoo}{\refstepcounter{foo}\thefoo}
\begin{document}
\begin{tabular}{r|l}
\hline
\rfoo\label{f1} & First line \\ \hline
\rfoo\label{f2} & Second line \\ \hline
\hline
\end{tabular}
The first line is \ref{f1}. The second line is \ref{f2}.
\end{document}
Aqui a versão de numeração automática de linhas
\documentclass{article}
\usepackage{array}
\newcounter{foo}
\renewcommand{\thefoo}{(\roman{foo})}
% Define
\newcolumntype{R}{>{\refstepcounter{foo}\thefoo\arraybackslash}r}
\begin{document}
\begin{tabular}{R|l}
\hline
\label{f1} & First line \\ \hline
\label{f2} & Second line \\ \hline
& ... line \\ \hline
\label{f4} & ... line \\ \hline
\hline
\end{tabular}
\
The first line is \ref{f1}. The second line is \ref{f2}.
And in line \ref{f4} you can see that
\end{document}
Responder2
\label
gravação \theX
do último contador X
, então atualize isso de acordo:
\documentclass{article}
\newcounter{foo}
\renewcommand{\thefoo}{(\roman{foo})}
\newcommand{\rfoo}{\refstepcounter{foo}\thefoo}
\begin{document}
\begin{tabular}{r|l}
\hline
\rfoo\label{f1} & First line \\
\rfoo\label{f2} & Second line \\
\hline
\end{tabular}
The first line is~\ref{f1}. The second line is~\ref{f2}.
\end{document}
Como referência, vejaCompreender como funcionam as referências e rótulos.