TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I took this line from my thesis style and added it into my document (preceded by \makeatletter) and what it does that whenever I used \ref{figureid} instead of putting just the figure number, it puts "Figure 1".

I can do the same thing for tables, by having \def\p@table{Table~) but what I don't know is what exactly is:


I assume they're used internally by ref, but is there anything more (such as \p@(object) is always used as the beginning of something ...)

share|improve this question
Great question! Finally I understand what's happening in this post and the answers to this post. (Also nice answers so far.) – Hendrik Vogt Nov 23 '10 at 15:13
up vote 17 down vote accepted

These are LaTeX kernel macros that are associated with environments. In simple terms anything that is enclosed with a \begin{foo}...\end{foo} is an environment. For example a figure or a table.

Every time you insert a table a counter is incremented. This counter let us call it foo has an associated macro named \p@foo. This macro expands to a printed `reference prefix' of counter foo.

Any \ref to a value created by counter foo will produce the expansion of \p@foo\thefoo when the \label command is executed. \thefoo justs prints the value of counter `foo'.

Change foo to figure or table and it will make more sense.

The \def part defines the macro. You can for example say \def\milan{Milan Ramaiyan} and every time you type \milan it will expand too .. Milan Ramaiyan. The @ symbol is just a special symbol used by TeX and LaTeX to avoid overriding commands accidentally. It needs special treatment and that is why the makeatletter and makeatother are required.

share|improve this answer

In addition to Yiannis fine explanation: you may even extend these \p@ macros such as \p@figure to become more than just a prefix. source2e.pdf gives hints in section 53.2 An extension of counter referencing.

This modification

{\csname p@#1\expandafter\endcsname\csname the#1\endcsname}}

allows you to define \p@figure with an argument, which allows more sophistocated formatting. And it's still backwards compatible to the original version. An arbitrary example:


gives see figure (1). This way you may add a prefix and a suffix plus formatting.

share|improve this answer
I would strongly advise against redefining one of the base latex commands. It can break packages that redefine it, e.g. hyperref. Rather go down to a deeper level, for example to change the reference to a second level enumerated list from 2a to 2(a) \makeatletter \renewcommand{\p@enumii}{\expandafter\p@@enumii} \newcommand{\p@@enumii}[1]{\theenumi(#1)} \makeatother – Danie Els Mar 4 '11 at 8:47

A packaged alternative to Stefan's answer is to use the fncylab package, which makes the change he mentions and also defines a \labelformat macro to manipulate \p@counters easily. For example, \labelformat{equation}{(#1)} makes \ref act like \eqref when applied to labels on equations. (I have this activated by default in my documents, actually. The bare number is rarely useful.)

share|improve this answer

I used \usepackage{hyperref} and applied \autoref{tab:minimum-cut-set}. It would generate "Table 1.2" (for instance) what we want to see. However, for algorithm, although "Algorithm" capitalizes but it shows "algorithm 2.1" (for instance).

The caption table, figure are shown properly. Only algorithm occurs the issue as I have mentioned above.

share|improve this answer
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. :) – Paulo Cereda May 9 '12 at 16:12

Your Answer


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.