LaTeX forum ⇒ Math & ScienceHow to align Items in a Sum?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
User avatar
Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm

How to align Items in a Sum?

Postby Cham » Wed Jun 22, 2011 5:36 pm

I'm having a small alignment problem with the idex of a sum :
  1. \sum_{\substack{i,\, j \,=\, 1 \\ j \, \ne \, i}} A_{ij}


The = and \ne signs aren't properly aligned. How should we modifity that code to align the items properly ?
Last edited by Cham on Wed Jun 22, 2011 10:47 pm, edited 1 time in total.

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Wed Jun 22, 2011 5:46 pm

You can insert a vertical phantom, that is to say an appropriate box with hidden content.
  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage{amsmath}
  3.  
  4. \begin{document}
  5. \[
  6. \sum_{\substack{i,\, j\,=\, 1 \\ \hphantom{i,} j\,\ne\, i}} A_{ij}
  7. \]
  8. \end{document}



Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Wed Jun 22, 2011 6:05 pm

localghost wrote:You can insert a vertical phantom


I tried it. The alignment isn't perfect.

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Wed Jun 22, 2011 6:20 pm

Works fine for me. Please clarify in which way this is not satisfactory.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Wed Jun 22, 2011 6:27 pm

localghost wrote:Works fine for me. Please clarify in which way this is not satisfactory.


The "=" and "\ne" aren't exactly aligned. If you compile and watch the index closely, you'll notice a small (and noticeable) offset. It's ugly.

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Wed Jun 22, 2011 6:39 pm

I can't comprehend this.
Attachments
sum-index.png
The rendered output of the provided code.
sum-index.png (4.96 KiB) Viewed 6439 times
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
Stefan Kottwitz
Site Admin
Posts: 9568
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Jun 22, 2011 6:44 pm

Hi Cham,

since equations/inequalities have to be aligned at a relation symbol, you could use an aligned environment. Also here you can customize size and fine-tune spacing. For example:

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \begin{document}
  4. \[
  5. \sum_{\scriptsize\begin{aligned}i, j &= 1 \\[-4pt] j &\ne i\end{aligned}} A_{ij}
  6. \]
  7. \end{document}

Btw. Thorstens way with a phantom command is handy in many situations.

Stefan
LaTeX.org admin

User avatar
Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Wed Jun 22, 2011 10:47 pm

Stefan_K wrote:Hi Cham,

since equations/inequalities have to be aligned at a relation symbol, you could use an aligned environment. Also here you can customize size and fine-tune spacing. For example:

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \begin{document}
  4. \[
  5. \sum_{\scriptsize\begin{aligned}i, j &= 1 \\[-4pt] j &\ne i\end{aligned}} A_{ij}
  6. \]
  7. \end{document}



This code works fine. Thanks a lot for it !

User avatar
Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat Jul 02, 2011 5:52 am

I'm getting some warning messages in the log file about the previous formula :
LaTeX Font Warning: Command \scriptsize invalid in math mode on input line 222.


The formula associated to this warning message is this :
  1. \sum_{\scriptsize\begin{aligned} i, j &= 1 \\[-4pt] i &\ne j \end{aligned}}

Apparently, the \scriptsize command is not allowed, while the compiled formula is nicely looking on the PDF version. What's going on here ?

Is there a better way to code that double-sum, without getting that warning message ?


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 1 guest