Melt 2 tablespoons of the butter in a Dutch oven, add the chopped onions and sprinkle with 1/2 teaspoon salt and some freshly ground pepper. Stir. Cover and simmer slowly for 15 minutes, checking that onions do not burn.
Preheat the oven to 350°F Butter a 2-quart rectangular or oval baking dish 14 inches by 8 inches by 2 inches.
Overlap one-third of the potato slices in one layer; season with 1/2 teaspoon salt and freshly ground pepper. Sprinkle on one-third of the Gruyere and half the braised onions. Continue with more layers, ending with cheese (do not salt the top layer). There will be only 2 layers of onions. Pour any remaining beer over the onions and dot the top with the remaining tablespoon of butter.
Bake on the middle shelf of the oven until potatoes are soft, about 1 to 1 1/2 hours.