The only option is to take a train from Malaga train station
to Ronda from where you can take another train to Algeciras.
If you ask for a ticket to Algeciras they should provide both tickets.
Once in La Linea de la Concepcion you can walk to Gibraltar
(approx. 30 minutes) or take a taxi.