All Ranged troops have a “fire at will” function: if toggled on they will automatically open fire on the first enemy unit that comes into range and remain locked on that target until you tell them otherwise. If it’s not toggled on they will do nothing unless you issue them an instruction.
Archers can be parked behind infantry because bow shots have a gentle arc and they will only cease firing when the enemy are too close. As others have said slingers fire in a flat arc so need to be in front of your infantry or they will not fire. At least they shouldn’t: the AI is not supposed to fire if there is a risk of hitting your own troops but often you will have significant friendly fire incidents.
All ranged troops have skirmish mode so you can put them out front with fire at will and skirmish mode on and they will lock on to approaching enemy units, only running behind your infantry lines when the enemy closes (provided you leave gaps for them to retreat through). Beware enemy cavalry charges though as the tactical retreat won’t be in time to save them.
Most infantry are hybrid troops to some extent: that is they have javelins / pila (Romans) and they will throw these before they charge and engage in melee combat, whether with sword, axe or spear. Only pikemen and some heavy duty spearmen like triarii or hoplites are “pure” melee troops.
Try and make use of your “hybrid” troops missile volleys before you charge them at specific units – they have a range of 40 yards and will automatically track approaching enemies and let loose. Any melee unit will fight when attacked but if they have no missiles and nothing is in range they will twiddle their thumbs until you tell them to attack an enemy unit.
I think most if not all units have a “formation attack” and “guard” button. The first means they will try and keep the width and depth of the formation you set them up in at the start so, depending on the angle you meet an enemy unit – head on or clipping at a slant – a lot of troops will be holding their orientation rather than wading around looking for an opening. If you take this off though they lose all shape and it can be hard to regroup and wheel them, say to face a cavalry attack with a shield wall or other special ability.
Guard means they will stay put rather than chasing any enemy unit so they might appear to be fighting if an enemy unit rushes them but if the enemy unit redeploys your men will be stood around guarding that patch of ground rather than chasing them down. It’s useful for defensive battles, particularly river crossings to block a bridge or ford and not get pulled out of position.
I failed the first prologue battle first time round as I couldn’t really tell what my troops were doing so it does come with familiarity.