We would like to take an overnight train from Krakow to Bratislava, stop for 4-5 hours in the morning, then travel on to Budapest in the afternoon. Could I book this on one ticket or do I have to book it as 2 separate tickets (which would probably cost more)?
It will need to be two tickets, one for each train.
According to the DB website ( https://www.bahn.com/en/view/index.shtml ), there is no through overnight train from Krakow to Bratislava. You would need to change trains in the middle of the night and arrive at Bratislava at 05:51. Not conducive to a good sleep:
Krakow Glowny dep 22:41, EN 407 (train is coming from Warsaw heading for Vienna), Breclav arr 04:14
Breclav dep 04:59, EN 477 (train is coming from Prague), Bratislava hl.st. arr 05:51
What date are you looking at? When I look at a random date, I see you have to change trains in Breclav at 4:15 am. Slovakian railways would not give me a price for Bratislava to Budapest, probably because they don't have print-at-home tickets for international trips. But buying a second ticket at Bratislava can't be that much. Czech trains are crazy cheap when bought in-country in the local currency.
The train which goes to Budapest, goes via Bratislava. The train originates in Warsaw, leaves Krakow 22:41, arrives in Bratislava 5:51, if you continue arrives in Budapest-Keleti at 8:35. So you can get by overnight train from Krakow to Bratislava without changing trains in Breclav. In Breclav there will be some disconnecting - part of the train will go to Vienna, the other part will be connected to train which originates in Prague and goes to Budapest, so you can sleep all the way Krakow to Bratislava or Budapest. You can find this schedule http://www.idos.cz which contains schedule for Czech Railroads. The train goes via Czech Republic.