GeneralIssue with \label and \ref

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
mecatuls
Posts: 17
Joined: Thu Jun 26, 2008 9:41 am

Issue with \label and \ref

Post by mecatuls »

Hi,

In my dissertation, I have to explain about lot of different cases. I want to give all a unique number and refer to them while discussing about these cases using figures or tables.

Now is there any way to label details of the cases in the beginning using \label command and then refer to them later where ever i want using \ref command. I want to do this, so that if I want to change the "case number" later on, I can do it without changing it everywhere manually.

Please suggest a way out.

Thanks and Regards,
Atul

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Issue with \label and \ref

Post by phi »

Hello,

the basic procedure is always as follows: You create a new counter, say case, and increase this for every case via the \refstepcase command. Then you can use \label and \ref as with any other sectioning command. Here is a small example:

Code: Select all

\documentclass{article}

\newcounter{case}

\newcommand*\case{%
	\refstepcounter{case}%
	Case \arabic{case}: %
}


\begin{document}

\section{ABC}

\case foo
\label{mycase1}

\case bar
\label{mycase2}

\section{DEF}

As discussed in case \ref{mycase2}\ldots

\end{document}
If you choose this way, you have to do all the formatting etc. by hand (and you have the greatest possible control). There are many packages that provide format templates, in most cases customizable. On example is the \newtheorem command from the LaTeX kernel, which is extended by the amsthm package.
mecatuls
Posts: 17
Joined: Thu Jun 26, 2008 9:41 am

Re: Issue with \label and \ref

Post by mecatuls »

Hi, Thanks a lot for the information. This is what I was looking for.
Regards,
Atul
Post Reply