OK - I was about to change oil when I saw this - so here goes.
Using a plum bob and string I measured from the outside of the two stock exhaust headers on my installed, stock, 99 Ranger - that width was 21" - once you measure from the outer edge of the alternator to the outer edge the PS pump right below the AC the width is 26". The engine is 30" high using a board against the bottom of the pan, and measuring as well as possible to the top of the intake plenum. From the mating edge of the back of the block at the transmission - to the face of the radiator (The fan ought to be pretty close to the radiator) was 28" that is a poor measurement because I can't see the fan and it tilts back slightly from the radiator. . . and BTW the frame rails at a point parallel to the sway bar is 26"
As far as the length of the Ranger engine bay is concerned it looks like from the face of the firewall to the back of the radiator is about 29".
If you add from the back of the block - the additional space required for a flex plate or flywheel. The engine should sit tightly - fully assembled - in a cube 30" long, 26 inches wide, 30" tall. In other words you could shut the lid on a box that size with a fully assembled engine.
All these measurements are + or - as much as an inch, not proof that anything will fit in your Ranger of that same size, or that your 4.0 will fit into anything else. It is worth therefore, exactly what you paid for it. But, I hope it helps.