我创建了一个自定义环境,让表格的第一列成为带有标签的计数器,可以在整个文本中引用。我不知道如何隐藏标题列中的计数器标签 (1)。以下是我尝试的方法:
\documentclass{article}
\title{MWE of Issue}
\author{me}
\usepackage{tabularx}
% this is the custom counter
\newcounter{slots}
\newenvironment{planar}
{
\begin{flushleft}
\begin{tabular}{>{(\refstepcounter{slots}\theslots)}rlll}
\setcounter{slots}{0} %resetting counter after header
Pos. & Type & Elements & Forms \\
}
{
\end{tabular}
\end{flushleft}
}
\begin{document}
\maketitle
Some text here.
% here's a table using the custom counter
\begin{planar}
\label{a} & itemA & aboutA & moreA \\
\label{b} & itemB & aboutB & moreB \\
\label{c} & itemC & aboutC & moreC \\
\label{d} & itemD & aboutD & moreD \\
\end{planar}
% here are some references to the labels from the custom counter
Sometimes I want to reference something about itemC with a ref \ref{c}, but other times, I need to talk about itemA with a ref \ref{a} more.
\end{document}
我怎样才能在标题列中隐藏这个标签,即防止它显示出来?
答案1
这是完整的 MWE,以防其他人遇到这个问题。它接管了这里正如评论中提到的,但对我来说,它只是在没有序言中重置计数器的行的情况下编译。如果您需要第二个重新开始计数的表,对我有用的是定义一个新的计数器。
\documentclass{article}
\title{MWE of Issue}
\author{me}
\usepackage{tabularx}
% define the counter
\newcounter{slots}
\def\rownumber{}
% define counter for other table
\newcounter{slotsb}
\def\rownumberb{}
\begin{document}
\maketitle
Some text here.
% use the counter in a table with a header
\begin{tabular}{>{\rownumber}rlll} \gdef\rownumber{\refstepcounter{slots}(\theslots)}
Pos. & Type & Elements & Forms \\
\label{a} & itemA & aboutA & moreA \\
\label{b} & itemB & aboutB & moreB \\
\label{c} & itemC & aboutC & moreC \\
\label{d} & itemD & aboutD & moreD \\
\end{tabular}
% here are some references to the labels from the custom counter
Sometimes I want to reference something about itemC with a ref \ref{c}, but other times, I need to talk about itemA with a ref \ref{a} more.
% use the other counter in a new table with a header
\begin{tabular}{>{\rownumberb}rlll} \gdef\rownumberb{\refstepcounter{slotsb}(\theslotsb)}
Pos. & Type & Elements & Forms \\
\label{d} & itemD & aboutD & moreD \\
\label{e} & itemE & aboutE & moreE \\
\end{tabular}
\end{document}