1

I created a custom environment to have the first column of a table be a counter with labels that can be referred to throughout the text. I can't figure out how to suppress the counter label (1) in the header column. Here's what I tried:

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

And here is the output showing the additional label in the header row and the correct references from the labels: output

How can I suppress this label in the header column, i.e. prevent it from showing up?

4
  • tex.stackexchange.com/a/21245/134144 might be interesting.
    – leandriis
    Apr 16, 2021 at 17:00
  • thanks, I tried the solution mentioned there, but it either prints a (0) in the header (instead of the 1 I get now) or I don't see how to have labels there I can refer to later.
    – SandraA.
    Apr 16, 2021 at 17:24
  • @SandraA. from the proposed duplicate the second approach in the accepted answer (with \def\rownumber{} in the preamble and \begin{tabular}{>{\rownumber}rlll} \gdef\rownumber{\refstepcounter{slots}(\theslots)} in the table) seems to work ok for your document as well.
    – Marijn
    Apr 16, 2021 at 21:10
  • It does yes, thank you. For me, however, it only compiles without \preto\tabular{\setcounter{slots}{0}} in the preamble.
    – SandraA.
    Apr 17, 2021 at 10:50

1 Answer 1

1

Here's the complete MWE that works, in case someone else is struggling with this issue. It's taken over from here as mentioned in the comments, but for me it only compiled without the line in the preamble that resets the counter. If you need a second table that starts over with the counting, what worked for me is defining a new counter.

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

And here's the output: mwe

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .