How do trains cross borders?

Before 1945, to prevent the transport of troops, countries organised their rail systems in an entirely independent fashion.
As a result, every country’s rail system is different. Even today, to cross a border, a train has to adapt to:

How do trains cross borders?