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 ...)

  • 1
    Great question! Finally I understand what's happening in this post and the answers to this post. (Also nice answers so far.) Nov 23, 2010 at 15:13

4 Answers 4


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.


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.

  • 2
    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, 2011 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.)


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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .