I was thinking you could have a battery in a train, that is charged by pantographs at the station. Accelerating out of the station will use a lot of energy so for a mile or so there could be pantographs and then they won't be needed for a few miles whilst the train runs off the battery. The battery can be charged when slowing down for the station using regenerative braking and charged whilst idling at the station.
This might be more complex and expensive though than just having the pantographs the full length of the line, but I thought about it recently when my local line was closed as a tunnel on it was too small to fit the pantographs through and had to be rebuilt.
Some are doing this with buses on fixed routes. There are even experiments with trucks and pantographs, electrified rails and even wireless charging on limited sections of highways (in Sweden and Germany I believe).
This might be more complex and expensive though than just having the pantographs the full length of the line, but I thought about it recently when my local line was closed as a tunnel on it was too small to fit the pantographs through and had to be rebuilt.