![生成连续编号的引用,例如要求](https://linux22.com/image/458291/%E7%94%9F%E6%88%90%E8%BF%9E%E7%BB%AD%E7%BC%96%E5%8F%B7%E7%9A%84%E5%BC%95%E7%94%A8%EF%BC%8C%E4%BE%8B%E5%A6%82%E8%A6%81%E6%B1%82.png)
我想创建一个包含项目要求的表格。
\begin{table}[H]
\centering
\begin{tabularx}{\textwidth}{C{0.1}L{0.75}C{0.15}}
\toprule
\textbf{R\hyp{}ID} & \textbf{Requirement Description} & \textbf{Priority} \\
\midrule
R1 & Requirement 1 & 1 \\
R2 & Requirement 2 & 1 \\
\bottomrule
\end{tabularx}
\caption{Ziele}
\label{tab:goals}
\end{table}
我现在想要做的是,标记 R1、R2,并可以从文本中引用,例如\cref{requirement-1}
。
创建 R1 / R2 条目的命令应该是可定制的:标签前缀和文本前缀在\uniqueReference{requirement}{R}
哪里。requirement
R
\begin{table}[H]
\centering
\begin{tabularx}{\textwidth}{C{0.1}L{0.75}C{0.15}}
\toprule
\textbf{R\hyp{}ID} & \textbf{Requirement Description} & \textbf{Priority} \\
\midrule
\uniqueReference{requirement}{R} & Requirement 1 & 1 \\
\uniqueReference{requirement}{R} & Requirement 2 & 1 \\
\bottomrule
\end{tabularx}
\caption{Ziele}
\label{tab:goals}
\end{table}
有没有可以实现这个功能的包?还是我必须创建一个自定义命令?
答案1
我找到了答案。
首先,检查一下这个问题LaTeX 中的引用表格行。
user31729 对行和列都使用了计数器。如果您想要全局唯一引用计数,只需在每次启动环境时删除重置机制即可。\AtBeginEnvironment{tabular}{\setcounter{rowcntr}{0}}
然后您可以定义一个新的计数器,例如:
\newcounter{rowcntr}
\renewcommand{\therowcntr}{\arabic{rowcntr}}
% A new columntype to apply automatic stepping
\newcolumntype{N}{>{\refstepcounter{rowcntr}}c}
我希望这能实现你想要做的事情。这是 MWE 代码:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[danish]{babel}
\usepackage{lscape}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{float}
\usepackage{array}
\usepackage[top=2.81cm, bottom=2.75cm,right=2cm, left=2cm]{geometry}
\usepackage{etoolbox}
\usepackage{setspace}
\onehalfspacing
\usepackage{url}
\usepackage[hidelinks]{hyperref}
\hypersetup{breaklinks=true}
\newcounter{rowcntr}
\renewcommand{\therowcntr}{\arabic{rowcntr}}
% A new columntype to apply automatic stepping
\newcolumntype{N}{>{\refstepcounter{rowcntr}}c}
% Reset the rowcntr counter at each new tabular
%\AtBeginEnvironment{tabular}{\setcounter{rowcntr}{-1}}
\begin{document}
\begin{table}[H]
\centering
\caption{Table with questions} \label{tab:Q1}
\begin{tabular}{|N|c|l|l|}
\hline
Theory & Question & Explanation \\ \hline
\label{que:whyisit} B & Why is it you think ... & This is a good question \\
\label{que:doyouthink} A & Do you think ... & This Is also a good question \\
\label{que:isitcorrect} B & is it correct that you think ... & This is question \\ \hline
\end{tabular}
\end{table}
Question \ref{que:whyisit} is about ... \\
Question \ref{que:doyouthink} is about ... \\
Question \ref{que:isitcorrect} is about ...
\newpage
\begin{table}[H]
\centering
\caption{Table with questions} \label{tab:Q2}
\begin{tabular}{|N|c|l|l|}
\hline
Theory & Question & Explanation \\ \hline
\label{que:whyisit2} B & Why is it you think ... & This is a good question \\
\label{que:doyouthink2} A & Do you think ... & This Is also a good question \\
\label{que:isitcorrect2} B & is it correct that you think ... & This is question \\ \hline
\end{tabular}
\end{table}
Question \ref{que:whyisit2} is about ...
Question \ref{que:doyouthink2} is about ...
Question \ref{que:isitcorrect2} is about ...
\end{document}