-1

for some reason i need to make many tables with latex, and non of them should have caption nor labels, but they need to be numbered like Subsection.tableNo. I have tried to use

\begin{tabular}{ccc}  
...& ... & No.: \arabic{subsection}.\arabic{table}\\\hline
.....
\end{tabular}

however, because i'm using only tabular environment, the table counter will not be set, so i always get like this:

... ... 1.0

... ... 1.0

... ... 2.0

... ... 2.0

how can i get the tabular counted? thx

(and..sry for my poor english)

tyker1
  • 123
  • 8

1 Answers1

1

You can use etoolbox to tap into the beginning of an environment <env> using \AtBeginEnvironment{<env>}{<stuff>}:

enter image description here

\documentclass{article}
\usepackage{etoolbox}
\AtBeginEnvironment{tabular}{\refstepcounter{table}}

\newcommand{\showtabular}{% Just for this example
  \begin{tabular}{|c|}
    \hline
    \thesection.\thetable \\
    \hline
  \end{tabular}}
\begin{document}

\section{First section}
\showtabular
\showtabular

\section{Second section}
\showtabular
\showtabular
\showtabular

\section{Last section}
\showtabular
\showtabular
\showtabular
\showtabular

\end{document}

Above I step (actually, the step can be referenced) the table counter with every new \begin{tabular}.

Werner
  • 14,324
  • 7
  • 55
  • 77