The number of fish in a SW aquarium is not real easy to determine. It is affected by the kind of fish, their temperament, the area of the tank they occupy, their habits, etc..
here are a couple examples
in a 40 gallon you can have a dwarf lion, even though it is a bigger fish its habits don’t include him needing space to swim. But you can’t house any fish he can eat which seriously limits the additional tank mates because you can’t have large fish in a 40 gallon. You could do another lion or maybe a small species of scorpion fish.
in that same tank you can’t do a fish like a flasher wrasse which is small but needs length to swim. its habits make it inappropriate.
you can’t have a dragonet. It is a small fish but it’s feeding habits make it necessary to have a very large tank I order to have enough food.
in a 40 gal you can’t have a damsel because they have nasty temperament and will harass any other fish to death.
if you want a lion fish and only have a 40b you will probably need to stick to a species tank.