Generalreferring to custom counters

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
evaristegalois
Posts: 3
Joined: Sun Feb 15, 2015 6:11 pm

referring to custom counters

Post by evaristegalois »

I have used LaTeX for a long time, but here is something I couldn't figure out even after vigorous googling (duckduckgoing, actually).

I am using a custom counter to number examples that I am giving throughout a long paper.

Code: Select all

\newcounter{expls}
...

\addtocounter{expls}{1}
...

\textbf{Example \arabic{expls}: \addtocounter{expls}{1} Example 1.

...

\textbf{Example \arabic{expls}: \addtocounter{expls}{1} Example 2.

...

\textbf{Example \arabic{expls}: \addtocounter{expls}{1} Example 3.

...
Sometimes I want to refer to these examples. To refer to an equation or a section, I can use \ref{}, for example "see Section \ref{sectionref}". how can I label and then refer to custom counters like expls above, like "see Example \ref{exampleref}" where of course I have to label the examples somehow.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

referring to custom counters

Post by Johannes_B »

Hi and welcome,

\addtocounter is wrong here. You are better off by using \refstepcounter.


Please have a look, at an answer i just wrote the other day.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
evaristegalois
Posts: 3
Joined: Sun Feb 15, 2015 6:11 pm

referring to custom counters

Post by evaristegalois »

Thank you, Johannes_B. refstepcounter works! This link also helps:

http://latex-community.org/forum/viewto ... 44&t=10815
Post Reply