Consumer surplus before tariff: light blue plus dark blue plus purple

Consumer surplus after tariff: light blue

Producer surplus before tariff: green plus yellow plus red

Producer surplus after tariff: red

Government gain from tariff: dark blue plus green

Why there is a net national gain: the nation consists of consumers plus government but does not include the producers since they are foreign.  Thus:

So the dark blue area just passes from consumers to government but is not lost by the nation.  The purple area is lost by the nation, but the green area is gained.  Because in this example  the green area and is bigger than the purple area, there's a net national gain.