Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Reading manuals I always find figure labeled as \label{fig:name}. I wonder where is the advantage of using this notation with fig:instead to start with the name it self. If in my document I have only figures when I \ref something using the label without fig: is more quick because I don't have to type fig: before to find the right figure that I want. Is there any advantage I'm missing? Should I use fig:?

enter image description here

share|improve this question
5  
If you have sure that you will only have labels for figures you don't need fig:. But in other cases, it is very recommended since you can quickly find the figure labels or table labels or section labels and so on... –  Sigur Jan 2 at 22:41
    
@Sigur thanks ok so however is arbitrary if I use f is the same thing... –  G M Jan 2 at 22:43
6  
@GM Labels are completely arbitrary (as long as they consist of ASCII characters only). However a personal naming scheme is surely good: with several internal cross references it becomes difficult to keep track of them and some helper is useful. –  egreg Jan 2 at 22:47
    
In fact it's a convention that is useful for know what object are you making a reference (usually you put a lebel only in the objects you want to refer later). So if you have a lot of labels to diferents objects, is useful the convention {IDobject: object name}. –  Aradnix Jan 3 at 1:01
1  
I usually put '.fig' at the end of the label instead of 'fig:' at the beginning. The reason being that half the time, by the time I've typed "\ref{fig:", I've forgotten what the label name is. –  Nathaniel Jan 3 at 2:06
show 1 more comment

4 Answers

up vote 40 down vote accepted

Here are at least two reasons:

  • It expresses the meaning of the label in a very sensible way, in all the below cases the intent of the label is straightforward and it will also let you group things that have meaning to each other, fig:system and eq:system have the meaning of system and one is a figure, the other an equation.

    • fig: for figures
    • tbl:/tabl: for tables
    • eq: for equations
    • chap:/chp: for chapters
    • sec: for sections
  • It can typically be parsed by your editor to easier lookup only figure/table/equation labels. In the case of emacs there is RefTeX which eases the cross-reference system. Several other editors also have such instances of cross-reference system.

share|improve this answer
add comment

In addition to the reasons given by others (intelligibility of source; leveraging editor capabilities etc.), if you use fancyref, you can automate more descriptive cross-referencing. This makes it easy to ensure that your cross-references are consistently formatted throughout the document. The system can be adapted to use your own preferred prefixes and labels, and can be extended to cover cross-references to other elements of your document. It can handle both plain and vario referencing and offers upper and lower case referencing commands out of the box.

\documentclass{article}
\usepackage{fancyref}

\begin{document}

\section{A section}\label{sec:mysec}

\begin{figure}
  \centering \fbox{A figure}
  \caption{My figure}\label{fig:myfig}
\end{figure}

\Fref{sec:myothersec} will demonstrate that \fref{fig:myfig} is fantastic.

\section{Another section}\label{sec:myothersec}

\Fref{fig:myfig} showed whatever my figure showed in \fref{sec:mysec}.

\end{document}

fancyref demo

share|improve this answer
17  
cleveref provides a similar functionality without the need of identifiers like fig:. But using them is still a good idea … –  Tobi Jan 3 at 1:48
    
cleveref looks really nice. Not so much because of the automated identification (though it does rather undercut my answer here!) but because it promises to automatically compress multiple references which is something I've wished fancyref could do. I will definitely have to take a look. I'm guessing you are the author? Thanks! (Though I guess I would lose my current config which is definitely a disincentive!) –  cfr Jan 3 at 2:01
    
No no … I’m just a user of the package :-) –  Tobi Jan 3 at 2:05
1  
Ah, well. Thanks for the pointer in any case. I notice now that he spells his name with a y not an i. –  cfr Jan 3 at 2:06
    
Oh … I never noticed that the author has nearly the same name :-) –  Tobi Jan 3 at 2:11
add comment

Personally I have never used such a convention (and LaTeX doesn't assume any structure to the labels) the label string is really just an opaque internal identifier. If you find it convenient to give a common prefix to labels of similar objects then do so, but it is certainly not a requirement of the system. Some packages and/or editors may try to parse the structure of the labels and look for fig: etc, but probably they shouldn't.

share|improve this answer
add comment

I'm currently writing some lecture notes for "Geometry and Topology" (in German). With that project I've learned why namespaces for labels make sense.

Avoid double labels: I have had problems without prefixes like fig: and sec: or bsp: (for examples) or thm:, because of double labels. Quite often, I have had a figure I want to reference and a theorem. Namespaces solve that problem nicely.

Make code easier to read

Avoid mix-ups: Sometimes, I wanted to reference sections. So I was sure the section had a label, e.g. \label{lifting}. But in fact, that label was chosen for a figure. This would not have happened when I had prefixes. With prefixes, LaTeX would produce some ?? and make it obvious that I made an error.

After I have seen the screenshot from above, I think there is another advantage for you:

Autocompletion: I guess most of the time you know if you want to reference a figure, a section, a table or whatever. This way, you reduce the number of elements you actually need to think about quite a lot. (By the way, what editor do you use? I still type my LaTeX with gEdit / pluma mot of the time ... maybe you have a better alternative?)

Cleveref and Fancref: There are some reasons why you should use \usepackage{cleveref} (see long answer). With that, you can do something like

\usepackage[nameinlink]{cleveref}
 ...
 As you can see in \cref{sec:abc} ...

which might translate to

 As you can see in section 7

where "section 7" is linked. Additionally, you can pass language options to cleveref which might make translation easier.

So there are some important reasons for using your own convention for label-namespaces.

Collaboration is the only reason for using a "well known namespace scheme" like fig: for figures and sec: for sections.

However, LaTeX doesn't care about label namespaces. They are just a part of the name of the label.

share|improve this answer
    
It's texmaker with different colors...In mac I use texmaker in Windows texstudio. They are more easy to use rather Vim or emacs with their latex plugin (or gedit but I never tried his latex plugin). –  G M Jan 8 at 22:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
http://tex.stackexchange.com/questions/152196/what-is-the-advantage-of-using-the-notation-fig-in-the-label
tex.stackexchange.com
crawl=CC-MAIN-2014-15
93286
application/http; msgtype=response
sha1:XCZETQW64P7BX7VYJTNUUYO26JVDC5JM
<urn:uuid:a210ad09-0409-4d22-a0cc-b698109ec4f9>
2014-04-25T05:24:56Z
198.252.206.140
sha1:RB5FETB27PRYV5GLUNVDKNLYWNX53DIT
<urn:uuid:72975330-c1ab-43a2-b641-48efb65e1826>
http://tex.stackexchange.com/questions/152196/what-is-the-advantage-of-using-the-notation-fig-in-the-label
response
<urn:uuid:fa8bb23e-6328-4816-9b4e-7fce4caa49b1>
robots: classic
hostname: ip-10-147-4-33.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2014-15
operator: CommonCrawl Admin
description: Wide crawl of the web with URLs provided by Blekko for April 2014
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf