How can I set the table counter?

32,113

Well, I may have misunderstood the question. But is it like this?

\documentclass[a4paper]{article}
\usepackage{enumitem}
\newlist{examples}{enumerate}{1}
\begin{document}
\setcounter{table}{4}
\begin{examples}[label=(\thetable.\arabic*)]
  \item {text to center}
  \item {text to center}
\end{examples}

\begin{table}[htb]
  \centering
  \begin{tabular}{|c|c|}
    \hline
    1 & 2 \\\hline
    3 & 4 \\
    \hline
  \end{tabular}
  \caption{This is one table}\label{tab:mytab}
\end{table}

\begin{examples}[label=(\thetable.\arabic*)]
  \item {text to center}
  \item {text to center}
\end{examples}

\end{document}

enter image description here

The settings of the list can be made global by

\setlist[examples]{label=(\thetable.\arabic*)}

Code:

\documentclass[a4paper]{article}
\usepackage{enumitem}
\newlist{examples}{enumerate}{1}
\setlist[examples]{label=(\thetable.\arabic*)}
\begin{document}
\setcounter{table}{4}
\begin{examples}
  \item {text to center}
  \item {text to center}
\end{examples}

\begin{table}[htb]
  \centering
  \begin{tabular}{|c|c|}
    \hline
    1 & 2 \\\hline
    3 & 4 \\
    \hline
  \end{tabular}
  \caption{This is one table}\label{tab:mytab}
\end{table}

\begin{examples}
  \item {text to center}
  \item {text to center}
\end{examples}

\end{document}

This will take the last value of \thetable as the first digit and second digit will be the usual arabic numbers.

Share:
32,113

Related videos on Youtube

Reactormonk
Author by

Reactormonk

Updated on June 12, 2020

Comments

  • Reactormonk
    Reactormonk over 3 years

    I've got my little examples env with

    \newlist{examples}{enumerate}{1}                          
    \setlist[examples]{label=(\arabic*), ref=\arabic*, resume}
    

    How do I use the same counter for the table env?

    • Peter Grill
      Peter Grill about 11 years
      I believe that it is simply table. So, \arabic{table} should yields its value? I am not sure what you want to do with it though. To access it's value you should refer to What is the proper method of accessing a counter?.
    • Peter Grill
      Peter Grill about 11 years
      Based on your title, perhaps you are looking for \setcounter{table}{<num>} to change the value of the table counter to a specific number?
    • Reactormonk
      Reactormonk about 11 years
      No, I want to sync the values of both counters - or use one counter for both envs.