Believe it or not, it actually takes a lot more effort to slouch than it does to maintain a straight* spine. The human skeleton is built to be vertical. That's right, the inertia we feel to shift our posture for the better is nothing other than bad habits dying hard.
The key to understanding and putting this into practice lies in sensing the head on the top of the spine. When the skull is resting centred and relaxed on the top of the spine, its weight, held in place by a ligament (connective tissue that connects bone to bone) that runs from the base of the back of the skull to your cerival spine (the bones that make up your neck), actually acts as a suspension system for the spine.
Put this into practice:
Stand (or sit) comfortably
Nod your head gently forward and back on the top of your spine. Start with a full range of motion, bringing the head as far forward to the chest as it will go and then lifting your chin to the ceiling and carefully allowing your head to tilt back.
Inhale and exhale deeply and allow any tension in your neck and head to melt away as you do this.
Gradually make this movment smaller and smaller. Bring awareness to the upper bones of your neck, see if you can sense the topmost joint between the skull and the spine and the weight of the head as it rocks incrementally forward and back.
Allow the head to come to a resting point, on the top of your spine. Notice the ease with which it can balance there and the lift it offers the rest of your spine when relaxed in place.
*A healthy spine is actually quite far from a straight line. Good posture consists of, if you're looking at a body sideways, a luscious S curve; curving towards the front of your body in your cervical spine (neck), towards the back of your body throughout your ribcage (thoracic spine) and then again towards the front of your body in your lumbar (lower back) spine.