When I am using phalanxes, I order each individual phalanx to attack a particular enemy unit rather than grouping them and giving orders to the group as a whole. They only break formation and engage with swords if they get flanked, so I usually have some cavalry on standby to prevent my phalanxes from being flanked.
I have only noticed the shuffle when I have about half a dozen phalanxes attacking a lone enemy unit, so some of my men have to budge up to make room for their comrades.
City streets often don't have enough room for attackers to stay in formation, so I disable phalanx mode when my pikemen are storming a city.
Phalanxes are supposed to engage the entire enemy infantry line simultaneously, but if you group your units and give them orders to attack as a group, the game thinks you want all your units to attack a particular enemy unit, so your men end up breaking formation. You definatly need to be a fan of micromanaging your battles to get the best out of phalanxes.
Bookmarks