225

It's easy to make subscripts in math mode: $a_i$.

How do I make a subscript outside math environment, likethis?

12 Answers 12

139

Note that \textsubscript enters math mode as well. This might produce problems in PDF strings where math is not allowed, for instance in bookmarks. If you used hyperref and simply used \textsubscript in a section heading, hyperref would complain about the math shift. The command \texorpdfstring comes to the rescue:

\documentclass{article}
\usepackage{fixltx2e}
\usepackage{hyperref}
\begin{document}
\section{\texorpdfstring{like\textsubscript{this}}{like this}}
\end{document}

That applies to math and math symbols in sectioning headings of course as well.

Since 2015, LaTeX provides the fixltx2e features by default, so you can omit \usepackage{fixltx2e}then.

  • 4
    Useful to know! NB: just to be clear, the \texorpdfstring command is in the hyperref package. Would any other package have problems with this? – Loop Space Aug 4 '10 at 14:12
  • 2
    pdftex could have problems. Try \pdfoutline goto page 1 {/Fit} count 0 {like\textsubscript{this}} and have a look at the bookmark. – Stefan Kottwitz Aug 4 '10 at 14:31
  • this is a neat trick ! I've had problems with math in section headers before. – Suresh Aug 4 '10 at 17:40
  • Do you have any recommendation for what is the preferred choice for setting subscript in LuaLaTeX? – ClintEastwood Nov 11 '14 at 9:33
  • @StefanKottwitz you might add some short recommendation about loading the package fixltx2e as one of the first packages. It has some incompatibilities (See this post) that can be solved in this way. I have been almost 1 hour debugging such a problem ( yes, my code was long, but even ). – loved.by.Jesus Oct 28 '15 at 13:56
103

This is included in the fixltx2e package:

\documentclass{article}
\usepackage{fixltx2e}

\begin{document}
like\textsubscript{this}
\end{document}

Interestingly (?), there's a \textsuperscript command already in LaTeX.

This is included already in the KOMA-Script bundle. If you want to typeset chemical formulas, have a look at the mchem package.

(Thanks to Caramdir for those last two.)

  • In @StefanKottwitz 's answer, he has used the same fixltx2e package. But he's also used the hyperref package. Is there a redundancy somewhere or am I missing something? – Shashank Sawant Oct 15 '12 at 17:42
  • 1
    @ShashankSawant Stefan's answer is: "if you use hyperref then you might want to do it like ..." So if you are already using hyperref and you want the subscript in headers, use his solution. Otherwise, this one ought to work. – Loop Space Oct 15 '12 at 19:17
  • 1
    As Fran points out below, it appears that \usepackage{fixltx2e} is no longer needed. – Isaac Mar 13 '17 at 15:53
  • 2
    fixltx2e is indeed no longer needed. See the CTAN page: "This pack­age does noth­ing other than is­sue a warn­ing in cur­rent LaTeX Re­leases." – chrisma Dec 21 '18 at 10:07
45

If you don't want to install additional packages you can use the following syntax:
like $_{\text{this}}$.

This will only require the use of one of the ams packages, for example amsmath, which is standard for most latex installations.

Alternatively, you can define a command \textunderscript in the beginning of your document:

\newcommand{\textunderscript}[1]{$_{\text{#1}}$}
  • 4
    \text needs the amstext package: perhaps you are thinking of \textup? – Joseph Wright Aug 4 '10 at 14:06
  • Yes, for \text you need one of ams packages (amsmath is enough), but I don't carry about that because I use amsmath in virtually all my latex documents. – fiktor Aug 4 '10 at 20:40
  • Or you could use \mathrm{}, or even nothing... It's so tiny no-one will notice... =P – daviewales May 15 '13 at 23:21
  • How do you use the command you defined? I tried a_1 and it results in an error. – Amir Sagiv Mar 5 '17 at 12:00
  • Amir, with the command from my answer you can write a\textunderscript{1}. But, please, take a look at the Fran's answer. – fiktor Mar 5 '17 at 18:16
44

Actual solution in LaTeX

Just write like\textsubscript{this}

You do not need preamble fixes anymore. Example:

\documentclass{article}
\begin{document}
    like\textsubscript{this}
\end{document}

Because all the fixes of package fixltx2e were enabled by default in the LaTeX format in 2015, the odd lack of this "expectable" command in LaTeX kernel is now history.

Old story

Just for the record: Before of the already cited fixltx2e package (now obsolete), the command \textsubscript was also supplied by exactly the same macro by the little package subscript (no longer in TeX Live):

\DeclareRobustCommand*\textsubscript[1]{\@textsubscript{\selectfont#1}}
\newcommand{\@textsubscript}[1]{{\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}}

But this command is still accessible in the changes packages that is actually the best option since is still in both MiKTeX and TeXLive.

\documentclass{article}
\usepackage{changes} % Not needed since 2015 
\begin{document}
like\textsubscript{this}
\end{document}

Another option could be a simpler user macro without \makeatletter stuff. To set the subscript size, the relsize package could help:

MWE

\documentclass{article}
\usepackage{relsize}
\def\textsubscript#1{\ensuremath{_{\mbox{\textscale{.6}{#1}}}}}
\begin{document}
\huge         a\textsubscript{th} A\textsubscript{th}\par
\Large        a\textsubscript{th} A\textsubscript{th}\par
\normalsize   a\textsubscript{th} A\textsubscript{th}\par
\small        a\textsubscript{th} A\textsubscript{th}\par
\footnotesize a\textsubscript{th} A\textsubscript{th}\par
\tiny         a\textsubscript{th} A\textsubscript{th}\par
\end{document}
  • 1
    This is exactly the same as Andrew's answer. – Werner Dec 15 '13 at 1:53
  • 3
    @Werner I don't think so. Andrew's answer is about the fixltx2e, I mention the older package subscript. I have not seen any mention to this package in any other answer. (and yes, I know that the command is exactly the same in both packages, I said "just for the record" for this reason...). – Fran Dec 15 '13 at 2:59
17

Since I've always been bugged by the fact that LaTeX's sscripts need math mode (setting normal text inside math mode have issues with LuaTeX's directionality), motivated by this question, I "stole" the subscript/superscript code from ConTeXt which is set entirely in text mode, with quick hacks to get it work with plain TeX (needs pdftex/luatex though), it is here for now, if there is interest may be it can be turned into some package.

  • 3
    As a bonus, it also provides a command, \lohi, to set sub and superscripts simultaneously. – Khaled Hosny Sep 3 '10 at 12:56
  • Neat. I vote for a package. – sgmoye Dec 15 '13 at 13:21
  • @KhaledHosny Can I ask whether this was ever made into a package? – solisoc Dec 6 at 9:44
  • @solisoc No it didn’t. – Khaled Hosny Dec 6 at 22:56
16

LaTeX provides \raisebox{<len>}{<stuff>} (based on TeX's \raise) which raises (and boxes) <stuff> by <len>. A negative <len> drops the contents:

enter image description here

\documentclass{article}
\begin{document}
It's easy to make subscripts in math mode: $a_i$.

How do I make a subscript outside math environment, 
like\raisebox{-.4ex}{\scriptsize this}?
\end{document}​
  • It seems like this nice trick does not work inside captions and tikz, am I wrong? – mmj Jun 15 '13 at 16:34
  • 3
    @mmj: Since it forms part of a moving argument, you have to use \protect\raisebox{..}{...}. – Werner Jun 15 '13 at 16:41
  • How do you know how much length to lower it? – Mario S. E. Feb 16 '16 at 13:40
  • @Mario S. E.: through trial and error I have come to -1/3 ex. – Raoul Kessels Apr 15 '16 at 10:05
14

In ConTeXt, you can write

like\low{this}
5

The way I do it is by using mathrm inside math environment:

$\mathrm{like_{this}}$
  • This and \text from amsmath are the simplest solutions. – Adam Erickson Jan 28 at 0:31
5

Here, I provide the subscript equivalent of this answer, Superscript outside math mode. I show how the subscript depth may be set, as well as the subscript size, using my stackengine package.

\documentclass{article}
\usepackage{fixltx2e}
\usepackage{stackengine}
\newcommand\textsub[1]{\stackengine{-.5ex}{}{\scriptsize#1}{O}{l}{F}{F}{L}}
\begin{document}
\noindent
a\textsubscript{th}A\textsubscript{th}\\
a\textsub{th}A\textsub{th}\\
\renewcommand\textsub[1]{\stackengine{-.4ex}{}{\footnotesize#1}{O}{l}{F}{F}{L}}
a\textsub{th}A\textsub{th}\\
\renewcommand\textsub[1]{\stackengine{-.5ex}{}{\tiny#1}{O}{l}{F}{F}{L}}
a\textsub{th}A\textsub{th}\\
\end{document}

enter image description here

  • In answer of community wiki (Fran) is stated that the package `'fixltx2e`` is obsolete. Why you still use it? Does stackengine work without it? – Zarko May 20 '15 at 0:45
  • 1
    @Zarko I need it only to show \textsubscript for comparison in row 1. The stackengine package does not need it. – Steven B. Segletes May 20 '15 at 0:46
  • B. Steglets, thank you for information. I found stackengine interesting for many my needs, but I still learning how to use it. Implementation of \textsubscript and \textsupercsript and combination of both are my first ongoing experimetns with it. – Zarko May 20 '15 at 0:54
  • @Zarko Best wishes! – Steven B. Segletes May 20 '15 at 1:09
4

If you use the $\text{}$ version and you have selected a different font (other than roman serif) then $\textnormal{}$ matches the font of the document. If you are using the default fonts, \text{} will work great.

3

I get this done by using the mhchem package. It's normally used for writing chemical formulas, but you can use it for this problem, too.

\usepackage[version=3]{mhchem}
\begin{document}
\ce{like_{this}}
\end{document}

mhchem doesn't print spaces when you put them in the subscript part. To get the spaces in the subscript part, you'll have to escape them using backslashes:

\usepackage[version=3]{mhchem}
\begin{document}
\ce{like_{this\ and\ this\ and\ this}}
\end{document}
-7

I am new to LaTeX but I have learnt reading the error messages they help a lot with the solution itself. That is where I found that without $ before and after your subscript function LaTeX would give your errors after quick build.

Like$_{this}$

Use $ to start and end the section of your command without these the math commands of subscript and superscript won't work. You don't need any additional packages for using these commands.

_{•} for subscript ^{•} for superscript

  • 1
    Welcome, there is a clear distinction between math mode and text mode, on a functional level and concerning fonts. You answer is very bad advice and will lead to confusion among new users. – Johannes_B Jun 11 '17 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.