Keeping your leg under you involves lots of practice to break old habits and develop muscle memory. If you are at a halt or walk, try going into two-point, then straightening your knee and hip angles as you slowly count to four. Sink into your heels. Then slowly count to four again as your lower yourself back into two point and extend your arms forward towards your horse's ears. If your leg moves, your center of gravity will change and your upper body will lose balance. To keep yourself from falling forward or backward you're forced to keep your leg in the proper position. This exercise is also great for your hamstrings.
You could practice with your strurruips tied to your girth to help train your leg of where it's supposed to be!!
Think about kneeling into you're saddle, also try no stirrup work.