yes, but they transport MUCH more people, they don’t have to stop at traffic lights, don’t get into traffic jams, and train tracks are more efficient in terms of friction.
So the fuel cost and amount of emissions per person is much less in most situations :)
Also, trains are much easier to electrify. A lot of European countries are doing this (or already have), as well as some US states. Electric locomotives already exist and are commercially viable, while electric cars are very much still in development and not available to most people. (Not to mention the infrastructure for them and the time it takes for the majority of people to switch to electric cars)
Also, there’s just much less locomotives than cars.
Same story with buses btw. Also, high quality and cheap public transport is much more friendly to poor/marginalized people who can’t afford a car, and better for disabled people who can’t drive