Q: How should we line up in prayer? Foot to foot or shoulder to shoulder? Is there another way?
A: After the Iqamah is called, it is recommended for the Imam to straighten the rows, lining up both the shoulders and ankles of those in the row, by saying “Straighten the rows, may Allah have mercy on you” on both the right and left side. It is also recommended to fill in the spaces by tightening the rows. This is done by some standing close enough to the others to touch. Note: Touching ankles or feet is not explicitly mentioned as a part of the recommendation but appears to be a means some may employ to reach compliance. Leaving gaps in the row does not invalidate the prayer be they behind or to the right of the Imam. Only a gap to the left of the Imam equivalent to three people would invalidate it. Source: Sharh al-Muntaha, al-Insaf, Matalib Uli al-Nuha