I want to use \tag in my LaTex file at https://www.sharelatex.com/.

For example, I want to do:

If $x \equiv x' \pmod{N}$ and $y \equiv y' \pmod{N}$, then: $xy \equiv x'y' \pmod{N}\tag{Substitution rule}$.

I look at a previous question on this website, \numcases with \tag, and found the answer insufficient for my problem.

I still get the ! Package amsmath Error: \tag not allowed here. error even though I am only importing the following:


I have two questions:

(1) Why does the amsmath package cause an error when \tag is used?
(2) How do I add customized tags to my equations without causing errors?

Thank you for any help you can provide on this!


This is a made-up example as requested:

Now solve for $E[X]$:\newline

    \hspace{30pt} $E[X] = 1 + E[X] - p \cdot E[X]$\newline

    \hspace{30pt} $0 = 1 - p \cdot E[X]\tag{"xyz"}$\newline

    \hspace{30pt} $p \cdot E[X] = 1\tag{"xyy"}$\newline

    \hspace{30pt} $E[X] = \frac{1}{p}\tag{"xzy"}$\newline\newline


Note the \tag parts were added in afterwards because they caused errors.

Then I want to say, based on "xyz" and "xyy", I can prove "abc".

  • 3
    I would guess it's because you're using it in inline math. 'Numbering' inline math seems weird to me. What exactly do you want to do? As it stands it looks like you may just as well use \text or write Substitution rule outside the math. Sep 9, 2013 at 8:48
  • @TorbjørnT. This is just an example, but I have other non-inline equations I want to write (e.g. equations at different points of a proof). I want to give them special \tag names like "Substitution rule".
    – user93172
    Sep 9, 2013 at 9:01
  • 1
    Can you then make a complete example with a displayed equation where it doesn't work? Sep 9, 2013 at 9:04
  • @TorbjørnT. Example added.
    – user93172
    Sep 9, 2013 at 9:21
  • 2
    @user93172 Those are still inline equations: the fact you are making them look like display doesn't make a difference.
    – Joseph Wright
    Sep 9, 2013 at 9:25

2 Answers 2


You're still using inline math. (La)TeX distinguishes between math that is supposed be written on a line of text, delimited by $ ... $ or \( ... \), and displayed math, which is placed on its own paragraph.

For a single unnumbered, displayed equation you can use \[ ... \], for a numberered equation there is \begin{equation} ... \end{equation}. For sets of equations, or multiline equations, amsmath provides several environment, including align and gather, as well as the starred forms align* and gather* that are unnumbered.

Displayed equations are by default centered, to make them left-aligned add fleqn as an option to amsmath or the document class, e.g. \usepackage[fleqn]{amsmath}.

For more information about amsmath, read the manual. For math typesetting in general, you could take a look at Herbert Voss' Mathmode.

A demonstration with your example:


Now solve for $E[X]$:
E[X] = 1 + E[X] - p \cdot E[X] \\
0 = 1 - p \cdot E[X]\tag{"xyz"} \\
p \cdot E[X] = 1\tag{"xyy"} \\
E[X] = \frac{1}{p}\tag{"xzy"}

Now solve for $E[X]$:
E[X] &= 1 + E[X] - p \cdot E[X] \\
0 &= 1 - p \cdot E[X]\tag{"xyz"} \\
p \cdot E[X] &= 1\tag{"xyy"} \\
E[X] &= \frac{1}{p}\tag{"xzy"}
  • Thank you for clearing up my confusion about inline vs. non-inline text! Thank you for the detailed rewriting of my code, which is an excellent example for me to work off of!
    – user93172
    Sep 9, 2013 at 9:46

These are still inline equations. You need to use

\[ formula \]



to make your formulas display style. Read about it here.

  • \end{formula} --> \end{equation}. Sep 9, 2013 at 9:28
  • Thank you for clearing up my confusion about inline vs. non-inline text!
    – user93172
    Sep 9, 2013 at 9:45
  • I recently got the "\tag not allowed here" error when I put a \tag inside \[...\]; but I was able to get the \tag to work inside \begin{equation}...\end{equation}, so it was no big deal. I was using a lot of packages; is this a known incompatibility?
    – MSC
    Oct 19, 2017 at 17:00
  • @MSC In short, the two are not equivalent; \[...\] is equivalent to \begin{displaymath}...\end{displaymath} and neither create equation numbers. For an excellent explanation, look at this very thorough answer. Oct 20, 2017 at 11:07

You must log in to answer this question.

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