The classic solution, IIRC, is to use 'field poles' ie cones or pyramids of high permeability material such as 'soft iron', to 'focus', 'concentrate' or otherwise shape the magnetic field of a magnet. Modern manufacturing techniques allow a magnet or an electromagnet's core to be custom shaped. Uh, some cores may be laminated to suppress losses due to eddy currents...
If you stack bar magnets together and restrain them against mutual attraction / repulsion, you can get interesting magnetic fields. A version of this is seen in eg fridge magnets that have little apparent field on one side...