
表内の行にローマ数字で番号を付け、相互参照するときに同じ方法で参照を印刷したいと考えています。
例えば、
\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}
与える
しかし、私が望んでいるのは:
答え1
各カウンターには と呼ばれるマクロがあり\the...
、たとえばカウンターfoo
には があります\thefoo
。この\the...
マクロは、デフォルトでカウンター値をアラビア数字で出力します。
\thefoo
は、ファイルに書き込まれるラベルにも使用されます.aux
。形式(i)
が要求された場合、これをファイルに書き込む必要があり.aux
、 で使用されます\thefoo
。
それで
\renewcommand{\thefoo}{(\roman{foo})}
それがゲームの名前です ;-)
\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}
ここでは自動行番号付けバージョン
\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}
答え2
\label
\theX
最後のカウンターの書き込みなX
ので、これに応じて更新します。
\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}
参考として、参照とラベルの仕組みを理解する。