I'm not sure if that's a fair comparison.
You're essentially comparing the cost of fuel versus the cost of: road infrastructure, costs of a vehicle, costs of a driver, costs of risk (insurance / safety), parking and servicing (cleanliness).
The train's parking space at the station and during off-hors is paid for your ticket, as are the tracks and tunnels it travels through, its trained driver, its safety measures, the cleaning and security personnel.
What you'd have to figure is, that the fuel might be $20. But you need to buy a car, pay for it monthly, pay for insurance, pay taxes indirectly to fund your roads, pay for your license and the police who ensure safety of the environment you drive in, enforcing the rules, you need to clean your car yourself and park it during off hours. All of those costs and some others (like say, maintenance/repairs) must be averaged into your car ride. And you'd need to divide that by the average amount of occupants, which is something like 1.2 for trips to work, not 4.
And then you get a typical long-term situation. I agree, it can be frustrating to think 'this car I already paid for, on a road which I pay for anyway, with this monthly insurance I already have, the license I already have, the 3 people I already have lined up to make this exact trip, and the police that's already in place to ensure a safe road, this trip is cheaper than the train'... But there's a lot to it as you can see, and it's not even a typical trip.
One important aspect about public transport is that it subsidises low-popularity roads. e.g. where I'm from, a bus ticket is basically the same price in the entire province, despite some routes earning no profit due to them just connecting small villages with a bunch of old people with bigger cities. The solution of say Uber would be to stop servicing or increase the price there to where it becomes economically feasible. The public transport approach is to not stop servicing or charge ridiculous rates, but simply to move money around so that everyone has a semblance of affordable transportation available. It's similar to post delivery, it's under pressure because there's no money to be made in lots of low-density areas. But there's something to be said for the ability to cheaply send a letter anywhere in the country for a roughly standardised price. That context too should be considered when comparing prices to very specific trips. You'd often end up comparing an averaged out transport mode price versus a specific high-occupancy car trip, cherry picking without the intention.