Moving from group 1 to group 7, i.e., along a period from left to right, there occurs an increase in nuclear charge as well as decrease in atomic size. Both these factors make the electrons tightly bound towards the nucleus, thus making it difficult for them to be lost. This increases the electron affinity.