Yes, No, Maybe.
First, you have to define what is the "best way"
Considering the technology for such a railgun is science fiction it's impossible to answer you without detailed parameters.
Firsts points to consider:
If the barrel end within the atmosphere, the shuttle will be subject depending on the altitude to:
- High drag
- Forces suffisant to kill any occupant
- Forces suffisant to destroy it
If the final speed is high enough, you are still suborbital (unless you reach escape velocity.
To reach space you need a horizontal component. Your perigee (lowest point of your orbit) will ALWAYS be at the lowest acceleration altitude. One other way to put it is that you always go back where you where originally, even if you accelerate a lot. You need a "circularization burn"
So now to try to answer you I'd say:
- If you want to escape earth, a vertical railgun is best
- If you want to orbit a horizontal railgun is best: you will gain the most speed from it (assuming you are vertical but do NOT follow the earth curvature, you'll still reach space).
- If you don't have illimited materials, the best angle will be somewhere in between, depending on your engineering requirements.
Now about 45 degrees, one would need detailed parameters to answer you, but yes this is a "good" angle. If I were to write a SF book with railguns on earth this would be my pick. Or the horizontal one, because that would look really awesome.
Of course it would be made of Unobtainium