我正在尝试获取测试计划的编号行。预期结果是第一列中的“1”、“2”等。但是,当 tabularray 处理表格时,它会在输出任何内容之前多次增加计数器,并且在每行之间多次增加计数器,或者看起来是这样的。示例代码:
\documentclass[10pt]{article}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{tabularray}
\geometry{hmargin={1.5in, 1.5in}}
\setstretch{1.2}
\usepackage[sc]{mathpazo}
\linespread{1.05}
\usepackage[T1]{fontenc}
\begin{document}
\section{Test}%
{\small
\newcounter{teststep}\setcounter{teststep}{0}
\begin{longtblr}{
hlines, vlines,
colspec={cXcccX},
column{2}={halign=l, valign=m, co=5},
column{6}={halign=l, co=2},
row{1}={halign=c, font=\bfseries},
rowhead=1
}
Step & Description & Min & Max & Unit & Measured \\
\refstepcounter{teststep}\arabic{teststep}
& Do a step.
& 1 & 100 & V & ~ \\
\refstepcounter{teststep}\arabic{teststep}\label{repstep}
& Do another step.
& 1 & 100 & A & ~ \\
\SetCell[c=6]{halign=j, valign=m, wd={\linewidth-18pt}} This line explains some things. It's a lot of text and wraps to multiple lines, and isn't numbered, and can't interrupt the numbering of steps around it. \\
\refstepcounter{teststep}\arabic{teststep}
& And like in Step~\ref{repstep}, another.
& 1 & 100 & W & ~ \\
\end{longtblr}
}
\end{document}
(我当然可以把\refstepcounter
东西放进它自己的里面\newcommand{}
,只是在这里写出来而已。)
结果:
如何防止数字增加?
答案1
tabularray
多次运行表的内容,因此,如果您需要更改tabularray
表内的计数器,则需要counter
库来恢复它们,可以使用来启用\UseTblrLibrary{counter}
。
\documentclass[10pt]{article}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\geometry{hmargin={1.5in, 1.5in}}
\setstretch{1.2}
\usepackage[sc]{mathpazo}
\linespread{1.05}
\usepackage[T1]{fontenc}
\begin{document}
\section{Test}%
{\small
\newcounter{teststep}\setcounter{teststep}{0}
\begin{longtblr}{
hlines, vlines,
colspec={cXcccX},
column{2}={halign=l, valign=m, co=5},
column{6}={halign=l, co=2},
row{1}={halign=c, font=\bfseries},
rowhead=1
}
Step & Description & Min & Max & Unit & Measured \\
\refstepcounter{teststep}\arabic{teststep}
& Do a step.
& 1 & 100 & V & ~ \\
\refstepcounter{teststep}\arabic{teststep}\label{repstep}
& Do another step.
& 1 & 100 & A & ~ \\
\SetCell[c=6]{halign=j, valign=m, wd={\linewidth-18pt}} This line explains some things. It's a lot of text and wraps to multiple lines, and isn't numbered, and can't interrupt the numbering of steps around it. \\
\refstepcounter{teststep}\arabic{teststep}
& And like in Step~\ref{repstep}, another.
& 1 & 100 & W & ~ \\
\end{longtblr}
}
\end{document}