You take the train:
- Some is paid to sell you a ticket
- Some is paid to drive the train
- Some is paid to "conduct" the train
- Some is paid to clean the train
- Some is paid to control the signals
- Fuel costs money
- Leasing the train costs money
- Leaving aside a percentage to cover "delay repay" costs money
- Maintaining the track costs money
Sometimes that can be several people required to perform those tasks, generally above the average UK salary (say over £25k - not intending to get into an argument about staff wages, just pointing out that there are a lot of highly skilled professional jobs in the railway industry). The ticket price is intended to reflect these kind of costs
If you drive then you are either doing all of those things yourself (driving, cleaning), or they are things paid for by general taxation (traffic lights, road maintenance) - other than fuel. And the fuel costs for a modern car are going to be relatively low (given improvements in mpg) compared to a train that may still be running a diesel engine from thirty years ago and therefore not very energy efficient.
So, if you are only comparing the price at the petrol pump with the cost of a train ticket then it's a bit like complaining that Air B&B is cheaper than a hotel (when a hotel means paying for receptionist/ cleaner/ security etc, rather than just renting a place).
I'm all for train travel being "affordable", but when you consider how many jobs there are to make sure that your journey works, I'm surprised that people are surprised at the fact that train travel generally costs more than you performing the majority of those tasks yourself.