Begin by preparing the onions, which should have their outer papery skins removed and then be cut in half lengthways from stem to root.
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.
Season the onions with salt and freshly milled black pepper, then scatter over the chopped thyme and sprinkle in the vinegar.
Turn the heat down under the pan and let the onions cook very gently for about 10 minutes.
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 by mixing all the ingredients in a processor until it resembles fine crumbs, then gradually add enough cold water to make a soft dough.
Pop the dough into the fridge in a polythene bag for 30 minutes to rest.
After the onions have cooked, test them with a skewer: they should be cooked through but still retain some texture.
Remove the pan from the oven and place it back on the hob, increasing the oven temperature to gas mark 6, 400°F (200°C).
Turn on the heat under the pan containing the onions to medium to reduce the buttery oniony juices for about 10 minutes.
Roll out the pastry to a circle about 10 inches (25.5 cm) in diameter, then fit the pastry over the onions, pushing down and tucking in the edges.
Return the tart to the oven on the higher shelf and give it another 25-30 minutes until the pastry is crisp and golden.
Allow the tart to cool for 20 minutes before turning it out.
Place a flat plate on top of the pan, turn it upside down, and shake to release the tart.
If any onions are left in the pan, lift them off with a palate knife and replace them into their own space in the tart.
Serve the tart just warm with a few shavings of Parmesan sprinkled over.
