I don't think there is a way to place them in a specific order. But you can always make rules so they fit correctly. For example you could define that tunnels/caves have a possible connection 20 blocks north from the south west and south east corner of all templates. If they don't there should be a cave-in at that place, a stub.
Now imagine two templates side by side. There are 4 possibilities:
1) Both have a tunnel connection at that position. They connect naturally
2) Only the west template has a connection, the east template not. It just looks like a cave-in made that tunnel end there
3) Only the east template has a connection, again it just looks like a natural dead-end there.
4) Both have no connection there, then it is just a small hole in the ground with no connection at all, you won't ever know it exists unless you decide to dig there by chance.