Preheat the oven to 170C/350F/Gas 4 and preheat a solid baking sheet as well.
Begin by preparing the onions, which should have their outer papery skins removed and then be cut in half lengthways from stem to root. After that, place the pan over a medium heat and, as soon as it's hot, add the butter and the sugar, then as soon as the butter begins to sizzle, quickly scatter the sprigs of thyme in, then arrange the onions on the base of the pan, cut side down. As you do this you need to think 'jigsaw puzzle', so that after the onion halves have been placed in the pan to cover the surface, all of those left over need to be cut into wedges and fitted in between to fit all of the gaps. Bear in mind that what you see when you turn the tart out, is the cut side of the onions.
When the onions have all been fitted in, give them a good seasoning of salt and freshly milled black pepper, then scatter over the chopped thyme and sprinkle in the vinegar. Now turn the heat down under the pan and let the onions cook very gently for about 10 minutes. After that, cover the pan with foil and place it on the baking sheet on the shelf just above the centre of the oven and leave it there for the onions to cook for 50-60 minutes.
While the onions are cooking, make the pastry and this, if you like, can be done by mixing all the ingredients in a processor. When the mixture resembles fine crumbs, gradually add enough cold water - about 2-3 tbsp - to make a soft dough. Then pop the dough into the fridge in a polythene bag for 30 minutes to rest.
As soon as the onions have had their cooking time, test them with a skewer: they should be cooked through, but still retain some texture. Then, protecting your hands well, remove the pan from the oven and place it back on to the hob, increasing the oven temperature to 200C/400F/Gas 6. Then turn on the heat under the pan containing the onions to medium, as what you now need to do is reduce all the lovely buttery onion juices - this will probably take about 10 minutes, but do watch them carefully so that they do not burn. By this time you'll be left with very little syrupy liquid at the base of the pan.
While that's all happening, roll out the pastry to a circle about 25cm/10in in diameter, then - again being careful to protect your hands - turn the heat off under the pan, fit the pastry over the onions, pushing down and tucking in the edges all round the inside of the pan. Then return the tart to the oven on the same baking sheet but this time on the higher shelf and give it another 25-30 minutes until the pastry is crisp and golden.
When the tart is cooked, remove it from the oven and allow it to cool for 20 minutes before turning it out. When turning it out it's important to have a completely flat plate or board. Then, protecting your hands with a tea cloth, place the plate on top of the pan, then turn it upside down, give it a good shake and hey presto - Red Onion Tarte Tatin! If for any reason some of the onions are still in the pan, fear not: all you need to do is lift them off with a palate knife and replace them into their own space in the tart. I think it's nice to serve this tart just warm with a few shavings of Parmesan sprinkled over.