Suppose I need to get a formula like $L^{2,3/4,5/6}_{1,2,3}$ in Latex. Then $2$--$1$, $3/4$--$2$, $5/6$--$3$ is not aligned. See
Then how can I let these three to be aligned?
- 37,268
- 383
-
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – Przemysław Scherwentke Nov 01 '13 at 05:02
-
2This just a notational crime against your readers! – percusse Nov 01 '13 at 11:02
6 Answers
Let us make things complicated.
\documentclass{article}
\usepackage{calc}
\begin{document}
$L^{2,3/4,5/6}_{1,\makebox[\widthof{3/4}]{$\scriptstyle 2,$}\makebox[\widthof{5/6}]{$\scriptstyle 3\hphantom{,}$}}$
\end{document}

I agree with Benjamin's comments. Hence an attempt to increase the spaces.
\documentclass{article}
\usepackage{calc}
\begin{document}
$L^{2,3/4,5/6}_{1,\makebox[\widthof{3/4}]{$\scriptstyle 2,$}\makebox[\widthof{5/6}]{$\scriptstyle 3\hphantom{,}$}}$
\end{document}

One can also resort to reduce the space before and after / by using
\newcommand*{\mybar}{\kern-.2ex/\kern-.2ex}
instead of /.
-
I think it is exactly what the OP wanted, but there is more spacing around the $/$ than around the $,$s, so my eye doesn't immediately group the $3/4$ together. All in all, I think the OP has chosen a poor notation to start with. – Benjamin McKay Nov 01 '13 at 09:04
Just for fun, with low level commands:
\documentclass{article}
\newcommand{\stacked}[2]{%
\vcenter{\tabskip=0pt
\gdef\separator{/}
\halign{$\scriptstyle##$\hfil&&$\scriptstyle\separator##$\hfil\cr
#1\cr
\noalign{\nointerlineskip\kern.2ex\gdef\separator{\phantom{/}}}
#2\crcr
\noalign{\kern.275ex}
}%
}%
}
\begin{document}
$L^{2/}_{1,}L\stacked{2,3&4,5&6}{1,&2,&3}$
\end{document}

If centered alignment is preferred, here's a (rather complicated) way.
\documentclass{article}
\usepackage{xparse}
\newlength{\commawidth}
\newcommand{\dostacked}[2]{%
\settowidth\commawidth{$\scriptstyle,\,$}
\vcenter{
\tabskip=0pt
\halign{\hfil$\scriptstyle##\vphantom{/}$\hfil\tabskip\commawidth
&&\hfil$\scriptstyle##\vphantom{/}$\hfil\cr
#1\cr
\noalign{\nointerlineskip\kern.2ex}
#2\crcr
\noalign{\kern.275ex}
}%
}%
\kern-\commawidth
}
\ExplSyntaxOn
\NewDocumentCommand{\nospacecomma}{}
{
\rlap{$\scriptstyle,$}
}
\cs_set_eq:NN \egreg_dostacked:nn \dostacked
\cs_generate_variant:Nn \egreg_dostacked:nn { xx }
\NewDocumentCommand{\stacked}{mm}
{
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\seq_set_split:Nnn \l_tmpb_seq { , } { #2 }
\egreg_dostacked:xx
{ \seq_use:Nn \l_tmpa_seq { \nospacecomma& } }
{ \seq_use:Nn \l_tmpb_seq { \nospacecomma& } }
}
\ExplSyntaxOff
\begin{document}
$L^{2/}_{1}L\stacked{2,3/4,5/6}{1,2,3}X$
\end{document}
The first L^{2/}{1} is just for comparing the heights, while the trailing $X$ is for checking that no space is added at the end.
Not the best code. But, hey, it works!

- 1,121,712
Using the tabstackengine package introduced at Writing a table with equally spaced columns, based on the widest column, we make the sub/super array a stack, and only have to tweak the space between the sub/super line and the vertical placement of the subscript line. A long stackgap of 6pt (vs. 7pt) matches the default sub/super placement, but the slashes in the superscript tend to interfere, so I increased it.
The alignment of the stack is centered, though an optional argument of [l] or [r] on the \tabbedVectorStack can change that.
\documentclass{article}
\usepackage{tabstackengine}
\begin{document}
\setstackgap{L}{7pt}% SUB- SUPER- BASELINE SHIFT
\( L_1^2 \textrm{~versus~} L\raisebox{0.5pt}% SUB- BASELINE
{\scriptsize\tabbedVectorstack{2,&3/4,&5/6\\1,&2,&3}} \)
\end{document}

- 237,551
-
1this could use a hair more space between the "rows"; the slash would be spearing the 2 if the slash were a little farther right. – barbara beeton Nov 02 '13 at 10:21
-
@barbarabeeton Thank you Barbara. I increased the gap from 6.5 to 7pt, based on your comment. – Steven B. Segletes Nov 04 '13 at 02:35

Code
\[
L^{2,3/4,5/6}_{1, \hspace{9pt}2, \hspace{8pt}3}
\]
Second Version: where phantom is used instead. Thanks for the comments, leading to improvement.

Code:
\[
L^{2,3/4,5/6}_{1,\phantom{3/}2,\phantom{5/}3} % This (shown here) aligns to the right.
\]
\[
L^{2,3/4,5/6}_{1,2\phantom{/4},3\phantom{/6}} % This (not shown here) aligns to the left.
\]
\[
L^{2,3/4,5/6}_{1,\phantom{3}2\phantom{4},\phantom{5}3\phantom{6}} % This (also not shown here) aligns to the center.
\]
Conclusion: Pair up with superscripts and use phantom appropriately.
- 29,686
-
3By hand? And what, if normal size is set to 11 or 12 pt? – Przemysław Scherwentke Nov 01 '13 at 04:34
-
@PrzemysławScherwentke -- Thanks for your comment, leading to a better result where the code is good for all size 10, 11, 12pt variations. – Jesse Nov 01 '13 at 05:09
-
-
-
in both examples, there should be more space to the right of the commas than to the left. as it is now, it's hard to recognize the slashed fractions as fractions. – barbara beeton Nov 02 '13 at 10:26
This is very simple and it almost works:
Almost: $ L^{2,}_{1,} {}^{3/4,}_{2,} {}^{5/6}_3 $

However, the first superscript (2,) is smaller than the others, hence slightly lower. So here's how to fix it without guesswork about the dimensions (now simplifed thanks to @sgmoye):
After: $ L^{2,\mathstrut}_{1,} {}^{3/4,}_{2,} {}^{5/6}_3 $

Note that in other examples, some exponents might be too big to fit in the space TeX reserves with a \mathstrut; you'd then need to reserve vertical space in a more general way. Here's a (somewhat clumsy) way to do that:
Version 3: $ L^{2,\llap{\phantom{\scriptsize /}}}_{1,} {}^{3/4,}_{2,} {}^{5/6}_3 $
Here, our model for vertical space is a (scriptsize) slash; but it could be anything. \phantom makes it invisible, and \llap ensures that it claims no horizontal space.
- 7,961
-
-
Yes! That's what I was looking for; tried regular
\strut(which wasn't right at all), but didn't think to try\mathstrutfor some reason. – alexis Nov 01 '13 at 12:33
L_{1,\phantom{3}2\phantom{4},\phantom{5}3\phantom{6}}^{2,3/4,5/6}

ADDENDUM:
The \phantom macro puts a blank space. The space size is equal to the horizontal size of the enclosed argument. For example, \phantom{3} puts a blank space with a length which is equal to the horizontal size of 3, etc... So, it mimics the effect of something in there that we can not see it ( that is why it's call "phantom" ).
- 191
-
1Please do not only write a line of code, explain what it is doing. Suppose the reader do not know what
\phantomdoes ... A good answer contains an explanation ... – Mensch Nov 02 '13 at 09:24 -
Isn't this basically the same as @Jesse answered in the second part of his answer? – cgnieder Nov 02 '13 at 19:46
-
@cgnieder Yes. It's true. I use \phantom{...} a lot. I like pretty short answers whenever it's possible. Thanks. – Felix Marin Nov 02 '13 at 19:49