Fernando Gaviria (Quick-Step Floors) took Stage 4 of the Tour of Britain in the tightest of finishes.