카운터 값을 원래 생성된 방식으로 인쇄하기 위해 \ref를 사용하는 방법은 무엇입니까?

카운터 값을 원래 생성된 방식으로 인쇄하기 위해 \ref를 사용하는 방법은 무엇입니까?

로마 숫자를 사용하여 테이블의 행에 번호를 매기고 상호 참조할 때 동일한 방식으로 참조가 인쇄되도록 하고 싶습니다.

예를 들어,

\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}

참고로 보세요참조 및 라벨 작동 방식 이해.

관련 정보