One of the main reasons for the disparity is the lower taxes that the aviation industry benefits from.
If you fly from Paris to Barcelona the airline not only pays no VAT, but is also exempt from kerosene tax. If you make the same journey by train, the rail company will pay an energy tax and passenger VAT. This means higher costs for the company which are usually reflected in ticket prices.
Archived version: https://archive.ph/7Zrur
From the experience of the Czech republic:
Most of the trains are run by private companies on behalf of the regional governments (chosen in a public competition). This has increased the quality of trains, while price (and, sadly, timetables) remains regulated by the region.
On the major lines, private companies operate also on their own, and even though the last-minute-in-rush-hour ticket are expensive, you can travel cheaply if you book it in advance and in less used hours.
(Also, until a year ago, one of the companies found a way how to misuse the governments’ discounts, making tickets for students&seniors practically costless/paid by state, but that’s another story.)