If you're sliding (not slouching), it's the chair.
You can do exercises to strengthen your abdominal and lower back muscles or your "core" muscles or whatever, and that will give you a naturally straighter posture.
Or just suck in the gut while sitting...