What is the best way to book train travel in Spain online in advance
With the company that actually runs the train.
For most parts of Spain that will be Renfe, www.renfe.com. But their website is not very user friendly, so for the main high speed routes I recommend their competitor Iryo, www.iryo.eu.
I’ve always used Renfe.com to book train tickets in Spain but here’s an excellent website that will give you comprehensive information about train travel in Spain & elsewhere:
seat61.com/Spain
I booked my train tickets on renfe.com. In terms of cost the website of the company that runs the train is the most obvious and best site to buy from. I suppose that other train ticket resellers that have a website in English would be "easier" to use. I suggest doing whatever you can to figure out RENFE's website; try to avoid having to buy from another ticket reseller. Similarly, for bus tickets, try to figure out the website of ALSA before resorting to buying from any other bus ticket-reselling website.