Why does he always slap my thigh?

So, my boyfriend always does this thing in public where he is sitting next to me and puts his hand around me so that his hand is on the side of my thigh and then occasionally just slaps that 'outside-facing' part of it. I get why he'd be doing this when we're alone, but why does he do this in public situations out of nowhere?
Why does he always slap my thigh?
Post Opinion