I've not done it for a long time, but as usual Seat61 has lots of info.
A practical guide for travel from London to Morocco by train & ferry, with recommended routes, train times & how to buy tickets.
www.seat61.com
He recommends getting a ferry from Tarifa rather than Algeciras as they still go to the town port in Tangier. There are free connecting buses from Algeciras for these ferries.
If you do end up in Tangier-Med there is indeed a bus to the town which he quotes a fare of 25Dh about 2.50 Euros.