352

If I want to use abbreviations for second, third and so on in my LaTeX documents, I am currently doing this: 2$^{nd}$ which seems unsatisfactory. Is there a macro I'm missing? I'm sure I could define one myself, and it would be fairly easy. But this looks like something that should already have been covered...

10 Answers 10

535

You should not use math, when it is normal text. Use \textsuperscript instead: 2\textsuperscript{nd}. You can also define a shortcut for this, e.g.

\newcommand{\ts}{\textsuperscript}

Then you could use 2\ts{nd} in the text.

Edit:
An even nicer solution is to load the package nth with the option super and use the \nth command:

\usepackage[super]{nth}
\nth{1}, \nth{2}, \nth{3}, \nth{4}
3
  • 5
    Is \nth{<number>} guaranteed not to be hyphenated? Commented Feb 16, 2013 at 12:48
  • 2
    @CodeMocker I think that would depend on your hyphenation rules. nth doesn't create a box for itself. I would never expect TeX to hyphenate such, though. Commented Feb 3, 2014 at 19:20
  • 2
    Options for the package are: % In LaTeX: % \usepackage[super,negative]{nth} % where option [super] gives superscript `th' % and option [negative] allows ``st, nd, rd'' suffixes on negative numbers.
    – semperos
    Commented May 11, 2017 at 12:36
136
+100

I guess the quickest and easiest solution is to simply write "2nd", "3rd", etc.

Superscripts aren't really necessary.

7
  • 151
    But where's the fun in that? Any chump can just write "2nd"...
    – Seamus
    Commented Oct 14, 2010 at 12:40
  • 42
    Unfortunately, sometimes life is a little bit boring – there are solutions that are both simple and correct. But as a consolation, bear in mind that most MS Word users will produce 2-superscript-nd accidentally, and they have no idea how to disable it. Commented Oct 14, 2010 at 12:49
  • 18
    Bringhurst (I think) does recommend against using superscript ordinals. But it's nice to be able to \nth things automatically, especially in math mode. Commented Oct 17, 2010 at 3:30
  • 18
    This is the correct answer! Remember that English is not French and does not put st, nd, th into superscripts!
    – yo'
    Commented Oct 24, 2012 at 11:48
  • 14
    To say "Superscripts aren't really necessary." Sort of misses the point given that we're already writing in LaTeX and so presumably we care enough about the formatting that the author of the OQ (or anyone else who arrived at this page later) probably already thought through that it would be easier to just write "2nd", "3rd" &c. and decided that they wanted to go through the trouble of having superscripted ordinals. And @tohecz even if a style guide says that a language does things in any particular way, generally (excepting (if you must?) the Académie Française) there is no correct answer.
    – mpacer
    Commented Dec 19, 2014 at 19:33
71

An alternative to nth package is fmtcount.

In this case the command is \ordinalnum. By default the ordinal is formatted as superscript, but this is optional, as it is also in nth:

\usepackage{fmtcount} % equivalent to \usepackage[super]{nth}
\usepackage[level]{fmtcount} % equivalent to \usepackage{nth}

But there are some advantages over nth:

  1. Limited multilingual support (English, French, Spanish, Portuguese, German and Italian). For example, in a Spanish document \nth{3} is formatted incorrectly as "3th" but \ordinalnum{3} is rendered almost correctly as "3º" (see addendum).

  2. Optional gender. For example \ordinalnum{3}[f] produces in Spanish the feminine ordinal "3ª" (tercera). There is also a neuter option (n). By default the gender is m (masculine).

  3. Is if possible switch between raise and level versions of ordinals in the same document (I can't imagine why, but who know!) with \fmtcountsetoptions{fmtord=raise} or \fmtcountsetoptions{fmtord=level}

  4. For English-only users, obviously (1) and (2) features are useless, but the ftmcount package has also many other ordinal commands, as \ordinal{counter} or \ordinalstring{counter} to print a counter as section as an ordinal ("3th") or as textual ordinal ("third") and more.

A third package, engord, also print numbers (\engordnumber{12}), counters (\engord{page}) and can switch between styles with \engordraisetrue or \engordraisefalse, but there are not multilingual or gender support.

On the other hand, for enumerated lists you can use the moreenum package with the labels \raisenth or \levelnth. A MWE:

\documentclass{article}
\usepackage{moreenum}
\begin{document}
\begin{enumerate}[label=\raisenth* --- ,start=1]
\item one
\item two
\item three
\end{enumerate}
\end{document}

Addendum: Ordinals in Spanish.

Although often not used, according to the RAE there must be a dot before the superscript, as in any abbreviation ended with a superscript as explained here. Then, the correct ordinal is "3.o" (tercero) or "3.er" (tercer) but not "3º".

In most cases one can just typing 1.º or 1.ª because is Spanish keyboards there are a key for the º ª \ symbols. However, the problem remain with numbers that can be ended by .er (1,3,13,21,23,31,33,etc.). Moreover, in some fonts the º and ª symbols are underlined (as in the keyboard), that it is correct in Spanish, but can produce inconsistencies if one type, for example, 1º,2º,3\textsuperscript{er},4º. Another problem is that these symbols are only in lower case even using \MakeUppercase.

The babel package take care of the format of Spanish abbreviations with a superscript suffix, and thus with the spanish option one can use n\sptext{os} to obtain for example n.os ("numbers" in plural), but moreover provide a shorthands for masculine and feminine ordinals (also in uppercase) using " which is not used in LaTeX for quotes. In this way, instead of 1\sptext{er} on can use just 1"er for example. In summary:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{bera}
\usepackage[spanish,es-noindentfirst]{babel}
\begin{document}

\subsubsection*{Lowercase}

1º, 2º, 3º ... 1ª, 2ª, 3ª \dotfill 
Keyboard input, incorrect (no dots). \\
1.º, 2.º, 3.º ... 1.ª, 2.ª, 3.ª 
\dotfill Keyboard input, correct but underlined.\\ 
1\sptext{o}, 2\sptext{o}, 3\sptext{o} ... 
1\sptext{a}, 2\sptext{a}, 3\sptext{a} 
\dotfill With Babel \verb|\sptext{}| command.\\
1"o, 2"o, 3"o ... 1"a 2"a 3"a \dotfill 
With "\ Babel shorthand.\\
1"er 2"o 3"er ... 1"a 2"a 3"a 
\dotfill Apocopate version (primer, tercer, etc.).

\subsubsection*{Upppercase}

\MakeUppercase{1.º, 2.ª, 3.\textsuperscript{er}} ...  
or ... 1.º, 2.ª, 3.\textsuperscript{ER}  
\dotfill (wrong way)\\
1"o 2"a  3"er  $\neq$ \MakeUppercase{1"o 2"a  3"er ... }  
or ...  1"O 2"A  3"ER 
\dotfill (babel way, correct)

\end{document}

MWE

1
  • 10
    The moreenum package actually just uses fmtcount at bottom. (I wrote the package: it's nice to see that a question I asked prompted my to write a package which then became an answer to that question.)
    – Seamus
    Commented Jan 10, 2013 at 11:14
25

If you are using ConTeXt MkIV, you can even imitate the automatic conversion of MS Word:

\usemodule[translate]
\translateinput[2nd][2\high{nd}]
\enableinputtranslation

\starttext
On the 2nd of November \unknown
\stoptext

This will translate all 2nd into 2\high{nd}.

4
  • 1
    Neat. How does this \translateinput work? It looks like XeTeX's input mapping but it must occur earlier in the processing. Commented Oct 17, 2010 at 3:28
  • I am not 100% sure on how it works. The translate module just registers a "user" filter. Looking at the source, this is how I understand what is happening. The input file is read line by line and first the input translation (encoding regimes and such) is done, then unicode translation (collapsing characters, etc) is done, and finally user translations are done. All this is done in the openers.textopen function in data-tex.lua file.
    – Aditya
    Commented Oct 17, 2010 at 7:38
  • Is it possible to implement \translateinput in LaTeX as well? Might come in handy.
    – marczellm
    Commented Jan 10, 2013 at 10:11
  • @marczellm: Since \translateinput is based on luatex, it is possible to implement it in LuaLaTeX. But I don't know how easy it will be to translate the ConTeXt code to LaTeX.
    – Aditya
    Commented Jan 10, 2013 at 20:24
21

If you're after speed when writing, this solution seems to be the quickest to type

\documentclass{article}
\usepackage{xspace}

\newcommand\nd{\textsuperscript{nd}\xspace}
\newcommand\rd{\textsuperscript{rd}\xspace}
\newcommand\nth{\textsuperscript{th}\xspace} %\th is taken already
\begin{document}
This is the 2\nd of December. Or the 4\nth of July. Or 3\rd place in a race.
\end{document}

The \xspace command intelligently decides whether there should be a space after the macro or not.

MWE

4
  • 3
    For maintain the space when appropriate you can use the package xspace. There are several questions about this package in the corresponding tag.
    – Fran
    Commented Jan 10, 2013 at 23:06
  • Thanks! Edited my answer to include xspace. Commented Jan 11, 2013 at 8:51
  • 3
    I know this answer is quite old, but the question Drawbacks of xspace is maybe worth to have a look at …
    – Tobi
    Commented Dec 12, 2013 at 13:35
  • 1
    This is my preferred approach as it makes the source code far nicer to read. Who wants to read \nth{4}? Commented May 6, 2014 at 3:04
7

Although this question is quite old and has very good answers, I think that maybe there are other people as type-lazy as me, who might appreciate my approach.

Edit: In response to egreg's comments, I wanted to adapt my answer - but the proposed changes would mean that the answer coincides with Nathanael Farley's answer, except for the fact that I redefined \th. egreg strongly cautions about compatibility issues with actually typing þ when redefining \th - use at your own risk.

In the interest of completeness, here's my original answer, which distinguished between math mode and text:

\documentclass{article}

\usepackage[english]{babel}
\usepackage{xspace}
\usepackage{mathtools} % only for \binom

\let\thorn\th % so that thorn-rune \th is not lost
\renewcommand{\th}{%
    \ifmmode% math mode
        ^\mathrm{th}%
    \else%
        \textsuperscript{th}\xspace%
    \fi%
}
% similar commands for \st \nd \rd (which are unoccupied)

\begin{document}
Works both in text (5\th, {\it 2\nd}, {\bf 1\st}, {\sf 3\rd})
and math mode $\displaystyle \left(
5\th, \, \binom{n}{5}\th, \, \sum_{1\st}^{n\th}\right).$
\end{document}

th-demo

This variant will always print upright letters in math mode, instead of adapting to the ambient text style. For a variant that adapts to the ambient style (e.g. italics in theorem environments, use \textsuperscript without distinguishing cases, see Nathanael Farley's answer).

I can imagine that someone might consider an exponent hidden in a macro bad form, but then, cases like n^2\nd seem far-fetched (and ugly), and I think it's obvious to anyone using LaTeX that this would need to be grouped. For powers, I guess I would prefer the inconsistency of $n^2$-th to $(n^2)\th$ anyway. These kinds of questions seem to be a hotly debated topic, see https://english.stackexchange.com/q/36512.

As a side note, I first tried to build an automatic \th which reads the previous character along the lines of How to find the previously printed character?, but managing \lastbox and the other primitives turned out to be way above my head. Also, even if this worked, writing 1\th is really not much quicker than writing 1\st (using the above), whereas the latter one is much more intuitive.

6
  • 1
    Even though it only an example, and my comments are not important, I can't help myself. (1) I don't see why is everyone so obsessed with \xspace, but it's your personal preference, just be sure that it's frowned upon in some journals. (2) You should definitely never need ordinals inside math. (3) Don't use \left(...\right), especially not for sums and integrals. Better try \biggl(...\biggr). (4) Many copy editors with change 1\st to 1st anyways (i.e., no superscript), so why all the fuss ...
    – yo'
    Commented Dec 11, 2013 at 16:03
  • Thanks for the comment. Short responses in order: (1) I have no experience with other solutions that avoid gobbled spaces, but am open to everything that works. (2) The math-examples are contrived, but $(n_1+1)\th$ isn't, and if the brackets are larger than the base size the superscript wouldn't be positioned correctly. Also, it's a compatibility precaution. (3) This was purely for bracketing the examples without overloading the MWE, I usually use \DeclarePairedDelimiter from mathtools (which are nicely scalable to the desired size).
    – Axel
    Commented Dec 11, 2013 at 16:24
  • 4
    Redefining \th is a very bad idea. Try using UTF-8 encoding and type a þ in your document. Of course, simply using \textsuperscript in every case is easier. And, finally, no: th shouldn't be superscripted.
    – egreg
    Commented Dec 12, 2013 at 10:44
  • Duly noted. I can see the reason to avoid redefining \th, but since I have never encountered (let alone used) the rune in question, I felt comfortable in taking this risk. Do you know of any package which uses this internally? You're right about needing no disambiguition if both are to be set in the ambient textstyle, but I like having the possibility of treating them differently (also I wasn't sure what xspace would do in math mode). Lastly, superscripting or not comes down to personal preference (various style guides notwithstanding), otherwise there wouldn't be interest in the question.
    – Axel
    Commented Dec 12, 2013 at 11:19
  • 1
    @Axel Please, use the @ mechanism to answer comments, so a notification is issued. Since \textsuperscript{th} in math mode does ^{\mbox{\fontsize\sf@size\selectfont #1}}, it seems useless doing \mathrm{th} in that case. So doing \newcommand{\nth}{\textsuperscript{th}} does better than the complicated macro you're using. Add \xspace, if you prefer; in math mode it does nothing.
    – egreg
    Commented Dec 12, 2013 at 11:39
3

nth package

Example

\documentclass[a5paper]{scrartcl}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[super]{nth}

\begin{document}
    The \verb+nth+ package is my \nth{1} choice when it comes to typsettingh
    nth-stuff. It might also be my \nth{2} and \nth{3} choice.
\end{document}

Results in

enter image description here

Limitations

1

The easiest and most beautiful way (in my opinion) is to input the ordinals as Unicode characters:

1ˢᵗ, 2ⁿᵈ, 3ʳᵈ, 4ᵗʰ, $i$ᵗʰ, $n$ᵗʰ

renders as

rendered ordinals

(I believe that requires LuaLaTeX or XeLaTeX and a supporting font.)

2
  • 2
    That's really interesting. Perhaps the packages above (e.g. nth) actually translate to the Unicode characters? Are they UTF8 compatible? Google is not helpful in this regard (presumably because it treats these phrases as stop words).
    – shiri
    Commented Nov 5, 2021 at 20:44
  • Maybe this requires a specific environment? When I use them in Overleaf like 17ᵗʰ August 2023 it just gives error messages, LaTeX Error: Unicode character ʰ (U+02B0).
    – AnnanFay
    Commented Aug 17, 2023 at 18:53
0

You could also simply write out the word. 1st = first, 2nd = second, and so on. Probably better in a formal setting anyway. If this is in a figure or table then any of the above answers sound great, but in a paragraph setting there's no need to get too cute.

-1

Using the amsmath package, you could to use the \text{} command in the math environment in the following way.

\usepackage{amsmath}

1$^{\text{st}}$
1
  • 4
    Welcome to TeX.SX! Do you think this is better than 1\textsuperscript{st}? Stylistic considerations aside. By the way, it is essentially the same internally, but much less efficient.
    – egreg
    Commented Oct 1, 2018 at 14:56

You must log in to answer this question.

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