Praise be to Allah.
He should stand in line with the imaam, not in front of him or behind him, but perfectly in line with him, on his right. This is how Abd-Allaah ibn Abbâs stood when he prayed with the Messenger of Allaah (peace and blessings of Allaah be upon him). In his Saheeh, al-Bukhaari entitled a chapter Baab yaqoomu an yameenihi al-Imaam bi hidhaaihi sawaa: idha kaanaa ithnayn (Chapter: he should stand on the right of the imaam in line with him if they are two). In this chapter he mentioned the hadeeth of Abdullah ibn Abbaas (may Allaah be pleased with him) who said: I stayed overnight in the house of my maternal aunt Maymoonah, and the Messenger of Allaah (peace and blessings of Allaah be upon him) prayed Isha, then he came and prayed four rakahs, then he slept, then he got up and I came and stood on his left, but he put me on his right and prayed five rakahs, then two rakahs, then he fell asleep and I heard his snoring. Then he went out for the prayer.
Ibn Abbaas (may Allaah be pleased with him) also said: I came to the Messenger of Allaah (peace and blessings of Allaah be upon him) at the end of the night and prayed behind him. He pulled me until I was in line with him, and when the Messenger of Allaah (peace and blessings of Allaah be upon him) turned back to his prayer, I went back to my original position behind him. The Messenger of Allaah (peace and blessings of Allaah be upon him) prayed, and when he had finished his prayer he said to me, What is going on? I made you stand in line with me and you moved back. I said, O Messenger of Allaah, is it right for anyone to pray alongside you when you are the Messenger of Allaah whom Allaah has blessed? He liked what I said and prayed that Allaah would increase me in knowledge and understanding. The hadeeth was narrated by Imaam Ahmad, 1/330 and classed as saheeh by al-Albaani. Its isnaad is in al-Silsilat al-Saheehah, 6060.
Then al-Albaani said: From this hadeeth we may understand that the Sunnah is when one man is praying alone following the imaam, he should stand alongside him on his right, not in front of him or behind him. This is the madhhab of the Hanbalis, as stated in Manaar al-Sabeel, 1/128.
Abd al-Razzaaq narrated that Ibn Jurayj said: I said to Ata: If a man prays with another man, where should he stand in relation to him? He said, To his right. I said, Should he be precisely in line with him so that neither is in front of the other? He said, Yes. I said, Do you prefer that they should stand close together so that there is no gap between them? He said, Yes.
In al-Muwatta it is narrated that Abd-Allaah ibn Utbah ibn Masood said: I entered upon Umar ibn al-Khattaab at midday and found him saying Tasbeeh (in the prayer). I stood behind him and he made me come closer until I was standing in line with him on his right.
Al-Haafiz said in al-Fath (2/191): Some of them narrated that there was scholarly consensus that one person praying alone with the imaam should stand to the right of the imaam.
And Allaah knows best.