The best thing is to pray with the Imam until he finishes including the witr as Imam Ahmad rahimahullah used to do and encourage:

سَمِعْتُ أَحْمَدَ، وَقِيلَ لَهُ: أَنْ يُصَلِّيَ الرَّجُلُ مَعَ النَّاسِ فِي رَمَضَانَ أَوْ وَحْدَهُ؟ قَالَ: يُصَلِّي مَعَ النَّاسِ، وَسَمِعْتُهُ أَيْضًا، يَقُولُ: يُعْجِبُنِي أَنْ يُصَلِّيَ مَعَ الْإِمَامِ وَيُوتِرَ مَعَهُ، قَالَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «إِنَّ الرَّجُلَ إِذَا قَامَ مَعَ الْإِمَامِ حَتَّى يَنْصَرِفَ كُتِبَ لَهُ بَقِيَّةُ لَيْلَتِهِ» قُلْتُ لِأَحْمَدَ ” الْإِمَامُ يُصَلِّي التَّرَاوِيحَ بِالنَّاسِ وَنَاسٌ فِي الْمَسْجِدِ يُصَلُّونَ لِأَنْفُسِهِمْ؟ فَقَالَ: لَا يُعْجِبُنِي، يُعْجِبُنِي أَنْ يُصَلُّوا مَعَ الْإِمَامِ، فَقِيلَ لِأَحْمَدَ، وَأَنَا أَسْمَعُ: يُوتِرُ الْإِمَامُ بِثَلَاثٍ، أُوتِرُ أَوْ أَنْصَرِفُ، فَأُوتِرُ وَحْدِي؟ قَالَ: تُوتِرُ مَعَهُ، قِيلَ: يَضِجُّونَ فِي الْقُنُوتِ؟ قَالَ: أَوْتِرْ مَعَهُ، قِيلَ لِأَحْمَدَ، وَأَنَا أَسْمَعُ: يُؤَخِّرُ الْقِيَامَ، يَعْنِي: التَّرَاوِيحَ إِلَى آخِرِ اللَّيْلِ؟ قَالَ: لَا، سُنَّةُ الْمُسْلِمِينَ أَحَبُّ إِلَيَّ “.
وَكَانَ أَحْمَدُ يَقُومُ مَعَ النَّاسِ حَتَّى يُوتِرَ مَعَهُمْ وَلَا يَنْصَرِفُ حَتَّى يَنْصَرِفَ الْإِمَامُ، شَهِدْتُهُ شَهْرَ رَمَضَانَ كُلَّهُ يُوتِرُ مَعَ إِمَامِهِ إِلَّا أُرَى لَيْلَةً لَمْ أَحْضِرْ

Abu Dawood said: I heard Ahmad: It was said to him: Should a man pray with the people in Ramadan or alone? He said: He prays with the people. And I heard him also say: It pleases me to pray with the Imam and make witr with him (since)
The Prophet (sal Allahu alaihi wa sallam) said: “Whoever stands (and prays) with the imam until he finishes, it will be recorded as if he spent the night in prayer.”
[Al-Tirmidhi, Abu Dawood, Al-Nasaa’i and Ibn Maajah – Classed as Sahih by Shaykh al-Albaani]

I said to Ahmad: the Imam leads the people in taraweeh and the people in the masjid pray by themselves? He said: No, it pleases me, it pleases me that they pray with the Imam, so it was said to Ahmad, and I heard: the Imam prays witr with three, so should I pray witr or leave and pray witr by myself? He said: you pray witr with him. It was said: they (the Imams) din (a loud, confused noise) in the Qunut? He said: pray witr with him. It was said to Ahmad and I heard: the imam delays the qiyaam ie. the taraweeh until end of the night? he said: no, the sunnah of the Muslims is more beloved to me.

Ahmad used to stand with the people until he made witr with them and he did not leave until the Imam left. I witnessed him all of the month Ramadan making witr with his Imam except one night (on which) he was not present.

[Masaail Imam Ahmad by Abu dawood no. 437-438]

But if one wants to pray witr later or pray more raka’at later then he adds one rakat to make it even.

Shaikh ibn Baz fatwa

بعض الناس إذا صلى مع الإمام الوتر وسلم الإمام قام وأتى بركعة ليكون وتره آخر الليل، فما حكم هذا العمل؟ وهل يعتبر انصرف مع الإمام؟

لا نعلم في هذا بأساً، نص عليه العلماء ولا حرج فيه حتى يكون وتره في آخر الليل. ويصدق عليه أنه قام مع الإمام حتى ينصرف، لأنه قام معه حتى انصرف الإمام وزاد ركعة لمصلحة شرعية حتى يكون وتره آخر الليل فلا بأس بهذا ولا يخرج به عن كونه ما قام مع الإمام، بل هو قام مع الإمام حتى انصرف لكنه لم ينصرف معه، بل تأخر قليلا

Question: Some people if they pray with the Imam witr and the Imam makes tasleem, they stand and make one rakah in order to make his witr at the end of the night, so what is the ruling on this action? And is it considered finishing with the Imam?

Answer: “We do not know in this any harm, texts from the scholars, and there is no harm in this until his witr is (prayed) at the end of the night. It is correct that he stood with the Imam until he finished because he stood with the Imam until he finished and he added one rakah for a legislated benefit until his witr is (prayed) at the end of the night, so there is no problem. He does not exit from being the one standing with the Imam, rather he stood with the Imam until he finished, however he did not finish with him, but he was delayed a little”

[taken from here]

Here is shaikh Bin Baz fatwa arguing that its better to finish with the Imam

~ Faisal Ibn Abdul Qaadir ibn Hassan Abu Sulaymaan