the following example shows that the self defined counter in the tabularx
environment does not start with "1". Can't figure out how to define the command to always start with "1". Ideas?
\documentclass{article}
\usepackage{enumitem}
\usepackage{cleveref}
\usepackage{etoolbox}
\usepackage{booktabs}
\usepackage{ltxtable}
\usepackage{ltablex}
\makeatletter\newcommand*{%
\CreateCounterIfNotExists}[1]{\begingroup%
\@ifundefined{c@#1}{\newcounter{#1}}{}%
\endgroup}\makeatother
\def\sdef#1{\expandafter\def\csname#1\endcsname}
\newcommand\requirement[3]{%
\CreateCounterIfNotExists{my#1}%
\sdef{themy#1}{#1\arabic{my#1}}%
\refstepcounter{my#1}%
\label{#2} #1\arabic{my#1}: #3%
}
\begin{document}
\requirement{A}{req:foo:a}{Starts with 1}
\requirement{A}{req:foo:b}{continues with 2}
\requirement{B}{req:hop:a}{Starts with 1}
\requirement{B}{req:hop:b}{continues with 2}
\begin{tabularx}{\textwidth}{lX}
\caption{Requirements}\\
\label{tbl:reqs}\\
\toprule
\textbf{Area}& \textbf{Description} \\\midrule
\requirement{C}{req:bar:A}{Starts with 3}
\requirement{C}{req:bar:B}{Continues with 4}
&
This should start with C1 \\\midrule
\end{tabularx}
\end{document}
cleveref
should be the last package, in most cases, but this is not the cause of your problems. Why do you think, it should start with 1 usingtabularx
?\ifltxcounter
frometoolbox
to test for the counter