Gravitational lensing by a structure in a cosmological background