Preheat the oven to 350°F (175°C).
Grease the baking dish with unsalted butter.
Slice the sweet potatoes into thin rounds (about ⅛ inch thick) using a mandoline or sharp knife.
In a medium saucepan, combine the heavy cream, minced garlic, salt, black pepper, and nutmeg. Heat over medium-low, stirring until warmed but not boiling. Remove from heat.
Begin layering the sweet potato slices in the greased baking dish. Pour a portion of the cream mixture over the first layer.
Sprinkle a portion of the Gruyère and Parmesan cheese over the cream.
Continue layering the sweet potatoes, cream, and cheese until all ingredients are used, finishing with a layer of cheese on top.
Cover the baking dish with aluminum foil and bake in the preheated oven for 30 minutes.
Remove the foil and bake for an additional 15 minutes, or until the top is golden brown and bubbly.
Let the gratin cool for a few minutes before serving. Garnish with fresh thyme if desired.
For a twist, try adding sautéed onions or bacon for extra flavor.
You can prepare the gratin in advance and bake it just before serving.
The gratin is best enjoyed fresh but can be stored in the refrigerator for up to 3 days. Reheat in the oven to restore the texture.