I want to make a custom counter (example) and use that to count examples (duh...).
The problem starts when I want to add \label and \ref commands.
I set up the counters so the counter is displayed as the section number + counter number. I use refstepcounter to enable the \label \ref functionality, but all \ref commands just give me the counter number. Not the section+ counter number.
EG: I get 1, but I want 1.1.1
I attached a sample of the code for you. Any help is much appreciated.
Bjorn
Code: Select all
\documentclass[a4paper,12pt]{report}
\usepackage[a4paper,margin=2.5cm]{geometry}
\usepackage[pdftex,bookmarks,colorlinks=true,linkcolor=black]{hyperref}
\newcounter{example}
\newcommand{\example}{\refstepcounter{example} EXAMPLE \thesection.\theexample}
\setlength{\parindent}{0cm}
\begin{document}
\chapter{One}
\section{Introduction}\setcounter{example}{0}
\example \label{ex1}\\
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text \\
\example \\
this is a reference to example \ref{ex1}.\\
Here I would like to see "this is a reference to example 1.1.1".
\section{second section}\setcounter{example}{0}
\example \\
this is a reference to example \ref{ex1}.\\
Here I would like to see "this is a reference to example 1.1.1".
\chapter{Two}
\section{Introduction}\setcounter{example}{0}
\example \label{ex2}\\
\chapter{Three}
\section{Introduction}\setcounter{example}{0}
\example \label{ex3}\\
This is a reference to example \ref{ex2}.\\
Here I would like to see "this is a reference to example 2.1.1".
\end{document}