How can I steal things without getting caught?

To reliably steal, you need to get out of the guard's line of sight and stay there for a while.

Your chance to be caught at thievery seems to correlate to the guard's awareness level of you. You can easily see your chance to fail as a percentage next to the item's name when you're about to loot it.

enter image description here

If the guard is in sight, you can also see how aware he is of you by entering stealth mode and looking at the icon over his head.

enter image description hereenter image description here

This means that a guard may not even be in the same room as you, but may notice you steal, simply because his "awareness" from when he last saw you hasn't worn off yet. His awareness will drop over time as you stay out of his sight. My experience is that the awareness level seems to drop for different guards at different rates... it was almost instantaneous for the guard in the alchemist's shop in Gorhart, but took longer for the guard in Shieldring Keep.