Book the Alhambra before you book the train
The order matters. Check ticket availability at tickets.alhambra-patronato.es first. If the Nasrid Palaces are sold out on your preferred date, either shift the date or plan a non-Alhambra day (Albaicín + Sacromonte + tapas is a genuinely good day). Booking the train first and then discovering you cannot get into the Alhambra is a common and fixable mistake — just fix it in the right order.