TransWikia.com

Alignment problem with large subscript in sum

TeX - LaTeX Asked by Tyson Williams on December 19, 2020

This MWE exhibits the problem I have:

documentclass{article}
usepackage{amsmath}
usepackage{mathtools}

begin{document}
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
[
 sum_{alpha in {a,b,c,d,e,f,g,h,i,j,k,ell,m,n,o,p,q,r,s,t,u,v,w,x,y,z}} 1 + alpha + alpha^2 + alpha^3 + alpha^4 + alpha^5 + alpha^6 + alpha^7 + alpha^8 + alpha^9
]
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.

Using ``mathclap'':
[
 sum_{mathclap{alpha in {a,b,c,d,e,f,g,h,i,j,k,ell,m,n,o,p,q,r,s,t,u,v,w,x,y,z}}} 1 + alpha + alpha^2 + alpha^3 + alpha^4 + alpha^5 + alpha^6 + alpha^7 + alpha^8 + alpha^9
]
end{document}

enter image description here

Question:

How can I implement the equivalent of moving the sum of alphas left (over top of the subscript of the sum) until they are right aligned to the right margin? The sum and its subscript should not move from its currently left aligned position.

3 Answers

If I have understood you correctly, then the sum of alphas (1 + alpha + ...) should be moved to the left to avoid the overful hbox warning:

documentclass{article}
usepackage{amsmath}

begin{document}
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
[
  sum_{alpha in {a,b,c,d,e,f,g,h,i,j,k,ell,m,n,o,p,q,r,s,t,u,v,w,x,y,z}}
  hspace{0pt minus 12.2pt}% value taken from the overful hbox message
  1 + alpha + alpha^2 + alpha^3 + alpha^4 + alpha^5 + alpha^6 + alpha^7 + alpha^8 + alpha^9
]
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
[
  sum_{alpha in {a,b,c,d,e,f,g,h,i,j,k,ell,m,n,o,p,q,r,s,t,u,v,w,x,y,z}}
  hspace{0pt minus 1fil}% allows natural width for the spacing around plus operators
  1 + alpha + alpha^2 + alpha^3 + alpha^4 + alpha^5 + alpha^6 + alpha^7 + alpha^8 + alpha^9
]
end{document}

Result

With avoiding the magic number

documentclass{article}
usepackage{amsmath}

newsaveboxtestbox

begin{document}
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
newcommand*{alphasum}[1]{%
  sum_{alpha in {a,b,c,d,e,f,g,h,i,j,k,ell,m,n,o,p,q,r,s,t,u,v,w,x,y,z}}
  hspace{0pt minus #1}
  1 + alpha + alpha^2 + alpha^3 + alpha^4 + alpha^5 + alpha^6 + alpha^7
}
sboxtestbox{$displaystylealphasum{0pt}$}%
[
  ifdimwdtestbox>linewidth
    alphasum{dimexprwdtestbox-linewidth}%
  else
    alphasum{0pt}%
  fi
]
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
This is a really long line of text to show where the margins of the page are.
[
  sum_{alpha in {a,b,c,d,e,f,g,h,i,j,k,ell,m,n,o,p,q,r,s,t,u,v,w,x,y,z}}
  hspace{0pt minus 1fil}
  1 + alpha + alpha^2 + alpha^3 + alpha^4 + alpha^5 + alpha^6 + alpha^7
]
end{document}

Result

Keep it simple

documentclass{article}
usepackage{amsmath}

begin{document}
[
  sum_{alpha in {a,b,c,dots, z}}
  hspace{0pt minus 1fil}
  1 + alpha + alpha^2 + alpha^3 + dots + alpha^9
]
end{document}

Result

Correct answer by Heiko Oberdiek on December 19, 2020

You can use smashoperator with include{mathtools}

smashoperator[r]{sumlimits_{parangaricutirimicuaro}} f(x).

I recently used it in an article and it worked charms. Hope it helps.

Answered by Jorge Fernández-Hidalgo on December 19, 2020

+1 for Heiko's answer, and in particular his advice about keeping it simple.

I would actually re-write your expression to use a local definition

screenshot

documentclass{article}
usepackage{amsmath}

begin{document}
[
  sum_{alpha in S}
  1 + alpha + alpha^2 + alpha^3 + dots + alpha^9
]
where
[
S={a,b,c,dots, z}
]
end{document}

Answered by cmhughes on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP