As this is pre the unification of the railways you can see the ways the two competing companies managed to reach both of the main towns.
The first railway to get to Thanet was the Southeastern and Chatham Railway the first station to open was in Ramsgate in 1846 as you see from the map it was at the top of the High Street, the present station, at the other end of Station Approach Road replaced it in 1924. Sometime after that (forgotten the date) the line was extended on to Margate.
Then came the London Chatham and Dover Railway via Margate that terminated at Ramsgate Sands Station that opened in 1863 and closed in 1926.
Now of course the two lines are connected together in a loop.
Click on the links below to look at to the information mentioned in this post.
Ramsgate and Historical Thanet
The early 1920s maps