01 - Preheat oven to 350°F. Generously butter a 2-quart gratin or casserole dish.
02 - In a saucepan, combine heavy cream, milk, garlic, nutmeg, salt, pepper, and thyme leaves. Warm gently over medium heat until steaming but not boiling, then remove from heat.
03 - Arrange half of the potato slices in overlapping layers in the prepared dish. Top evenly with half the onion slices (if using), half the Gruyère, and half the Parmesan cheese.
04 - Pour half of the warm cream mixture evenly over the layered potatoes and cheese.
05 - Repeat layering remaining potatoes, onions, Gruyère, and Parmesan. Gently press down to smooth the layers.
06 - Dot the surface with butter and sprinkle additional Gruyère cheese and a few thyme leaves.
07 - Cover the dish tightly with aluminum foil and bake for 40 minutes.
08 - Remove foil and bake an additional 20 minutes, or until golden brown and bubbling.
09 - Let the gratin rest for 10 minutes before serving. Garnish with fresh thyme leaves.