Leaning is an issue that is best corrected when a tree is young. A large leaning tree can pose a danger since it is more likely to fall down. Fortunately, leans can almost always be corrected in younger trees.
A lean is often the result of issues during planting, particularly if it shows up within a few months of putting the tree into the ground. The tree may be planted in the wrong location, for example. If sunlight is blocked by other trees or a building, then the young tree will begin to lean or put on heavy growth on one side as it reaches for sunlight. Another issue is if the tree was actually planted unevenly in the hole — in other words, if it was planted with a lean.
If the tree is still relatively small and is less than a couple of years old, then the simplest fix is to dig it up and replant it levelly and in a better location with the proper sun exposure. Otherwise, you may need to prune back neighboring trees in order to allow more light to reach the leaning tree.
Trees can also lean due to cultural problems. Typically this is from wet soil or shallow soils. With wet soil, the ground is more likely to heave due to temperature fluctuations. This soil heave can cause the tree to heave. Shallow soils don't provide sufficient depth for strong rooting, which means the tree isn't well anchored, so it will be more prone to leaning.
Aerating the soil around the roots can help improve drainage or loosen up the soil so the tree can root much more deeply. A tree service can perform a deep aeration if it is determined that this is the cause of your tree's lean.
Most young trees require some bracing. Bracing can also be used to help correct the lean for any of the issues above. For a young tree, it is usually only recommended to use a single cable to brace the tree. The cable is placed on the side opposite of the lean, at a height slightly below the crown. It is left in place for a least a year and sometimes two, depending on the severity of the lean.
Mature trees with a dangerous lean can also be braced, but this is typically to prevent a blowdown as it is less likely that the lean can be fully corrected once the tree reaches maturity. Multiple cables may be used for a mature tree.
Contact a tree service in your area if you have a leaning tree that needs to be trained.