Text Formattinga new kind of 'superscript'

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
casperyc
Posts: 50
Joined: Thu Oct 15, 2009 11:23 pm

a new kind of 'superscript'

Post by casperyc »

Hi all,

Code: Select all

$\mu_x^j$
looks fine here,

Code: Select all

$\mu_{x+s}^j$
does not really express as it should be.
is there a way to make the 'j' cetering to the 'x+s'?
so 'j' is actually 'above' '+' in this case?

just as if

Code: Select all

\mu_{\stackrel{j}{x+s}}
has shifted

Thanks.

casper

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

a new kind of 'superscript'

Post by gmedina »

Hi,

you could use something like the following:

Code: Select all

\documentclass{article}

\begin{document}

$\mu_{x+s}^{\phantom{x}j\phantom{s}}$

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
casperyc
Posts: 50
Joined: Thu Oct 15, 2009 11:23 pm

Re: a new kind of 'superscript'

Post by casperyc »

yes, that's exactly what i am using now.
however, if the subscript varies too much,
it is not confortable to use it.

e.g. for
\mu_{xxxx}^{j}

i might have to use '2.5' times of \phantom{x}?

Thanks.

casper
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

a new kind of 'superscript'

Post by gmedina »

Try this improved version:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\usepackage{ifthen}
\usepackage{calc}

\newlength\mylena
\newlength\mylenb
\newlength\mylenc
% syntax: \mysp{<base>}{<subscript>}{<superscript>}
\newcommand\mysp[3]{%
  \settowidth\mylena{$\scriptstyle _#2$}%
  \settowidth\mylenb{$\scriptstyle \sp{#3}$}%
  \ifthenelse{\mylena<\mylenb}
    {%
      \setlength\mylenc{\mylenb-\mylena}%
      #1_{\hbox{\hskip.5\mylenc$\scriptstyle #2$}}^{#3}%
    }
    {
      \setlength\mylenc{\mylena-\mylenb}
      #1_{#2}^{\hbox{\hskip.5\mylenc$\scriptstyle #3$}}%
    }%
}

\begin{document}

$\mysp{\mu}{xxxx}{j}$

$\mysp{\beta}{xxx}{j}$

$\mysp{\alpha}{x}{j}$

$\mysp{\mu}{x}{jjjj}$

$\mysp{\beta}{x}{jjj}$

$\mysp{\alpha}{x}{jj}$

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
casperyc
Posts: 50
Joined: Thu Oct 15, 2009 11:23 pm

a new kind of 'superscript'

Post by casperyc »

gmedina wrote:Try this improved version:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\usepackage{ifthen}
\usepackage{calc}

\newlength\mylena
\newlength\mylenb
\newlength\mylenc
% syntax: \mysp{<base>}{<subscript>}{<superscript>}
\newcommand\mysp[3]{%
  \settowidth\mylena{$\scriptstyle _#2$}%
  \settowidth\mylenb{$\scriptstyle \sp{#3}$}%
  \ifthenelse{\mylena<\mylenb}
    {%
      \setlength\mylenc{\mylenb-\mylena}%
      #1_{\hbox{\hskip.5\mylenc$\scriptstyle #2$}}^{#3}%
    }
    {
      \setlength\mylenc{\mylena-\mylenb}
      #1_{#2}^{\hbox{\hskip.5\mylenc$\scriptstyle #3$}}%
    }%
}

\begin{document}

$\mysp{\mu}{xxxx}{j}$

$\mysp{\beta}{xxx}{j}$

$\mysp{\alpha}{x}{j}$

$\mysp{\mu}{x}{jjjj}$

$\mysp{\beta}{x}{jjj}$

$\mysp{\alpha}{x}{jj}$

\end{document}
Thanks!

That works perfect!
Post Reply