Both during battle and while you travel through the world, your team is set in a specific combat formation. You can choose from three predefined settings: two columns, wedge or straight line. You can also create your own formations. That option gives you access to an area with 7x6 fields on which you can position your party members as you want. Each character uses one field so you many options. Creating your own formation is the best option as it gives you complete control over your companions position, but you must keep some rules in your mind.
Your team shouldn't be too extended to the sides. There shouldn't be more than three companions in one line. It will limit blocking in narrow passages. At front you should place fighter with a shield or another character that is focused on defense and taking damage. In the second row, just behind fighter, place other melee fighters, like barbarian, monk or animal companion. In third line magic classes should be positioned, like wizards or druids. Most of their spells require getting close to the target so they must be near warriors. At the end position rangers and other characters that fight using bows, crossbows or gunfire as they have the longest reach.
You can create two predefined formations and you should utilize both of them. Character placement shouldn't change, but distance between them can be adjusted. One formation should be used for fighting in buildings and dungeons, second for encounters in open space, like forests. Dungeon formation shouldn't have any empty spaces between companions. There is not much space for characters to move in narrow passages or tunnels. And you can't be attacked from sides so tight formation will be best. It's different when in open space. Here enemy can flank you at any time. The formation should be much less tight. Remember to keep the distance between the fighter at the front and the shooter at the back at least few fields. Thanks to that you will uncover bigger part of the map when you will walk through at and - what's most important - during battle your shooters will remain at safe distance from enemy. You won't waste time on retreating but you will be able to immediately get to fighting.
Changing between formations takes not more than 3 seconds and greatly improve your situation at the beginning of battle. When clicking and holding the right mouse button you can pick a direction towards which your party should be placed.