I am trying to put two subscripts at the left and right of a character. For example, something like: _{t} p_{x} where p is in the middle. How do you do this?
- 2@Alan: Why a comment?Caramdir– Caramdir2011-02-20 01:40:37 +00:00Commented Feb 20, 2011 at 1:40
- @Caramdir It just seemed so short. I've added it as an answer.Alan Munn– Alan Munn2011-02-20 01:51:00 +00:00Commented Feb 20, 2011 at 1:51
- 3Since this is essentially about left subscripts, you can also have a look at the answers to this question (possible duplicate).Hendrik Vogt– Hendrik Vogt2011-02-20 06:54:07 +00:00Commented Feb 20, 2011 at 6:54
- 6@Caramdir: The space has no effect in math mode ...Hendrik Vogt– Hendrik Vogt2011-02-20 06:57:05 +00:00Commented Feb 20, 2011 at 6:57
- 1@JPi: Done.......NebulousReveal– NebulousReveal2017-05-03 18:06:11 +00:00Commented May 3, 2017 at 18:06
12 Answers
There are many tools for scripts:
For general math scripts before something, use
\prescriptprovided bymathtools, for better alignment:$ \prescript{14}{2}{\mathbf{C}} $Alternatively, in order to have the left superscript indented to fit better with the shape of the symbol, use
\leftindexfrom theleftindexpackage:$ \leftindex^a_b {f}$
$ \leftindex[I]^a_b {L} $For large operators, use
\sidesetfromamsmath:$ \sideset{_a^b}{'}{\sum} A_n $For tensors, use
tensorpackage:$ M\indices{^a_b^{cd}_e} $
$ \tensor[^a_b^c_d]{M}{^a_b^c_d} $For chemical equations, use
mhchempackage:\ce{^{227}_{90}Th+}
Please complete this list as you can.
Source code:
\documentclass{minimal} \usepackage{mathtools,leftindex,tensor,mhchem} \begin{document} \verb!mathtools!: $ \prescript{14}{2}{\mathbf{C}} $ \medskip \verb!leftindex!: $ \leftindex^a_b {f}$, $\leftindex[I]^a_b {L} $ \medskip \verb!amsmath!: $ \displaystyle \sideset{_a^b}{'}{\sum} A_n $ \medskip \verb!tensor!: $ \tensor[^a_b^c_d]{M}{^a_b^c_d} $, $ M\indices{^a_b^{cd}_e} $ \medskip \verb!mhchem!: \ce{^{227}_{90}Th+} \end{document} - 26+1: I think that this is a great answer because it acknowledges the semantic element of LaTeX environments. Using
tensorfor, say, denoting an isotope is ontologically dodgy and its visual suitability is contingent on some hypothetical divergence of notation not occurring down the line.Richard Terrett– Richard Terrett2011-02-21 04:53:43 +00:00Commented Feb 21, 2011 at 4:53 - 3I tried most of these and found the \tensor solution the best one.Physics_maths– Physics_maths2014-04-29 12:20:28 +00:00Commented Apr 29, 2014 at 12:20
- Are there any options besides
mhchemthat don't require math mode? I'd like to typeset a downarrow before a letter in a phonetic transcription.Sjiveru– Sjiveru2018-07-19 23:37:21 +00:00Commented Jul 19, 2018 at 23:37 - @RichardTerrett Worth mentioning that the difference is not just of semantic adherence:
\sidesetwill only work with math operators, not with any item.Pietro Battiston– Pietro Battiston2019-12-11 20:15:36 +00:00Commented Dec 11, 2019 at 20:15 - Is there anything wrong (kerning?) with this simple approach? tex.stackexchange.com/a/317359/52160Pietro Battiston– Pietro Battiston2019-12-12 07:39:58 +00:00Commented Dec 12, 2019 at 7:39
Are you doing this in math mode?
${}_{t}p_{x}$
should work.
- 1Spaces are ignored in math mode.
$ _ t p _ x $produces exactly the same effect.TH.– TH.2011-02-20 05:31:07 +00:00Commented Feb 20, 2011 at 5:31 - 36I would go for
{}_{t}p_{x}, otherwise things like\sum _{t}p_{x}give surprising results.Bruno Le Floch– Bruno Le Floch2011-02-20 14:11:10 +00:00Commented Feb 20, 2011 at 14:11 - 4I think that the
tandxare not aligned using this approacha06e– a06e2013-12-02 22:22:47 +00:00Commented Dec 2, 2013 at 22:22 - 2@becko you'll need to match upper and lower i.e., ${}_{t} p_{x}$ and ${}_{t}^{} p_{x}^{n}$Juhl– Juhl2015-04-13 12:22:56 +00:00Commented Apr 13, 2015 at 12:22
- 5This is the best answer as it uses plain Latex without any need for extra packages.Andry– Andry2019-04-04 20:42:59 +00:00Commented Apr 4, 2019 at 20:42
The best solution I have seen so far was:
${}_{2}x_{1}$ For the more general case of left and right superscript and subscript, one writes:
${}^{1}_{2}x^{3}_{4}$ - The question is about two subscript, one before and one after. It's not the same as having an upperscript and a subscript at the same place.Romain Picot– Romain Picot2016-04-22 07:42:14 +00:00Commented Apr 22, 2016 at 7:42
- 2just added how you can have both in the same place and compared to some other solutions here I think this is rater simple in syntax.Asking Questions– Asking Questions2016-04-22 07:46:27 +00:00Commented Apr 22, 2016 at 7:46
- As I said, you put a subscript and an upperscript and not two subscriptRomain Picot– Romain Picot2016-04-22 07:48:36 +00:00Commented Apr 22, 2016 at 7:48
- ah ok I see your pointAsking Questions– Asking Questions2016-04-22 07:50:39 +00:00Commented Apr 22, 2016 at 7:50
- 1The indices are not aligned! :(Hosein Rahnama– Hosein Rahnama2016-11-29 16:44:16 +00:00Commented Nov 29, 2016 at 16:44
You could use the leftidx package which is capable of producing left and right subscripts and superscripts.
In contrast to using simply consecutive subscripts or superscripts such as in $_{t}p_{x}$ it takes care of adjusting indices to the argument using \vphantom. From its source:
\newcommand\leftidx[3]{% {\vphantom{#2}}#1#2#3% } - This is by far the best approach IMHO.Al_Fh– Al_Fh2019-09-30 09:05:05 +00:00Commented Sep 30, 2019 at 9:05
The tensor package will do exactly what you require, and more. For your particular case, you need only type
\tensor[_t]{p}{_x} Regards
The amsmath package has a \sideset command which lets you put indices at all four corners of a symbol (even if this symbol itself has limits above/below):
\[ \sideset{_t}{_x}p = \sideset{^*_*}{^*_*}\prod_*^* \] \sideset is intended to be used with large operator symbols such as \sum and \prod. The amsmath documentation says: this command is not designed to be applied to anything other than sum-class symbols. (Thanks to Stefan Kottwitz for this additional remark.) For other symbols, have a look at the other answers here.
- 14Good addition! Just a remark:
\sidesetis intended to be used with large operator symbols such as\sumand\prod. The amsmath documentation says: this command is not designed to be applied to anything other than sum-class symbols.2011-02-20 02:55:28 +00:00Commented Feb 20, 2011 at 2:55 - @Stefan: Ah, thanks ... I knew I should have looked it up before writing this. – So, don't use this with simple letter-symbols, use the other solutions given here.Paŭlo Ebermann– Paŭlo Ebermann2011-02-20 03:03:33 +00:00Commented Feb 20, 2011 at 3:03
A simple method I apply - which does away with the need for extra packages - is the following:
~^o\!G_{Al}^i Which produces the following: 
- 2Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. I think this solution is not ideal, because it will cause, at best, inconsistent spacing, or, at worst, a bad line break.Paul Gessler– Paul Gessler2014-10-25 13:56:30 +00:00Commented Oct 25, 2014 at 13:56
I had the same problem with the subscript and superscript, sooo I made a package to make my life easier and to other. It's a common problem with actuarial symbol, and it help align the sub and superscript. Plus, I’ve add some shortcut to save time.
The project page and the CTAN.
All you need is the actuarialsymbol package.
At the beginning of the code you have to write
\usepackage{actuarialsymbol} For the sub/superscript
\actsymb['subscripLeft']['superscriptL']{<middle>}{'subscriptR'}{'superscriptR'} Example of output:
- 1Welcome to LaTeX! Is this meant as an answer for another question?Moriambar– Moriambar2017-04-26 20:27:50 +00:00Commented Apr 26, 2017 at 20:27
- 1Congratulations! Nice package!Zarko– Zarko2017-04-26 20:33:39 +00:00Commented Apr 26, 2017 at 20:33
- 1@Moriambar it is: tex.stackexchange.com/a/366883 ;)cgnieder– cgnieder2017-04-26 20:35:07 +00:00Commented Apr 26, 2017 at 20:35
- @clemens My package can fulfill many problems.David Beauchemin– David Beauchemin2018-07-31 18:22:59 +00:00Commented Jul 31, 2018 at 18:22
- @Zarko thanks! If you have idea of upgrade we are open for it. We are working on a mathjax upgrade for ebook.David Beauchemin– David Beauchemin2018-07-31 18:23:46 +00:00Commented Jul 31, 2018 at 18:23
I am dissatisfied with the existing options, including \prescript from mathtools, since they do not even make an attempt at fixing the spacing between the symbol and the left superscript. Therefore, based on egreg’s excellent answer here, I recently added the package leftindex to CTAN. It provides the command
\leftindex^{<left superscript>}_{<left subscript>} {<symbol>} This measures the negative indentation of the right subscript and indents the left superscript by the same value. This works well for most symbols, with a few exceptions, such as A and L (and P and \Gamma in some fonts other than Computer Modern). Therefore, \leftindex takes a couple of optional arguments. The only one we shall need right now is
\leftindex[<slanting phantom>]^{<left superscript>} _{<left subscript>} {<symbol>} If the command receives a <slanting phantom>, it will use this symbol instead of <symbol> to calculate the indentation of the left superscript.
\documentclass{article} \usepackage{leftindex} \begin{document} Good results: $ \leftindex^a_b {f}, \leftindex^* {M}, \leftindex_q^p {H}, \displaystyle \leftindex_{-\infty}^{\infty} {\int} f(x)\, dx $ Bad results: $ \leftindex^* {A}, \leftindex^a_b {L} $ With slanting correction: $ \leftindex[T]^* {A}, \leftindex[I]^a_b {L} $ \end{document} If you grow tired of having to write slanting phantoms manually, you can have a look at my other package, SemanTeX, which provides semantic, keyval-based mathematics where notation can be controlled centrally from the preamble. Its left index support is based on leftindex, but slanting phantoms can now be chosen once and for all from the preamble:
\documentclass{article} \usepackage{semantex} \NewVariableClass\MyVar[output=\MyVar] % No slanting phantom needed: \NewObject\MyVar\vf{f} \NewObject\MyVar\vM{M} \NewObject\MyVar\vH{H} % Slanting phantom needed: \NewObject\MyVar\vL{L}[slanting phantom=I] \NewObject\MyVar\vGamma{\Gamma}[slanting phantom=] % Slanting phantom and a \!\! to the % right of the superscript needed: \NewObject\MyVar\vA{A}[ slanting phantom=I, post upper left=\!\!, ] \begin{document} $ \vf[upper left=a,lower left=b] $, $ \vM[upper left=*] $, $ \vH[upper left=p,lower left=q] $, $ \vA[upper left=*] $, $ \vL[upper left=a,lower left=b] $ \end{document} A solution I adopt, whenever I'm working in environments where extra packages are unavailable, is to manually adjust the index position by adding spaces...
For example
{}_{a+b}^c Z would result in
So, you could do
{}_{a+b}^{\quad c} Z which gives
But you have to adjust them "case by case" till you find it satisfactory, for example
{}_{ab+\prod x_i}^{\quad\quad\ c} Z Definitely, punk-LaTex, not ideal and not recommended, but sometimes useful when no better solution is available...
I made one little improvement on Henrik L's answer: I replace the ~ by {}
This removed the extra space given by ~
For my usage, this was important as I improved
$\Sigma _{~^{\wt M} \! M^{(m)} }^{0,+}$ which appears as
to
$\Sigma _{{}^{\wt M} \! M^{(m)} }^{0,+}$ which appears as
(ok, it's a complicated expression, but it's necessary, and this version makes it prettier!).
- 3Welcome to TeX.SX! Note that MathJaX/MathML is not supported on TeX.SX, so you may want to change
$$ $$into a screenshot :-)Teddy van Jerry– Teddy van Jerry2023-02-01 17:29:44 +00:00Commented Feb 1, 2023 at 17:29 - The question is about placing subscripts on the left and right of the main character, so this doesn't really provide an answer.Sandy G– Sandy G2023-02-01 19:48:31 +00:00Commented Feb 1, 2023 at 19:48
I forget where I got this. But Chemistry people have the same problem because they do need left superscript and subscript.
So use chemistry
\ce{^a\log b} This actually link the left superscript with the log after it. Also the spacing is reduced.
How to reduce the spacing in chemical symbols?
It works just fine here https://saxarona.github.io/mathjax-viewer/?input=%5Cce%7B%5Ea%5Clog+b%7D
But somehow it didn't work in tex stackexchange. I have no idea why
- Welcome to TeX.SE. Using the
mhchempackage was already part of the accepted answer. There is no need to add an other answer here.Alain Remillard– Alain Remillard2024-08-30 14:16:46 +00:00Commented Aug 30, 2024 at 14:16 - Also, it seems that your suggestion is to wrap any left index (including in non-chemistry settings) in
\ce. This is very wrong and will have about a million bad side effect.Gaussler– Gaussler2024-08-30 15:10:26 +00:00Commented Aug 30, 2024 at 15:10










