I have always known that you need to use the smallest f-stop you can in order to get the depth of field because I read it in all the photography books and in model railroading magazines. So I decided to see how critical is the f-stop to the depth of field. Below you can see a series of pictures that I took changing only the f-stop. These pictures were taken with my zoom lens set to 18mm which is a worse case for depth of field. I put the camera on the layout to take these pictures looking up the track. I figures the hard edge of the rails would give a good indicator of the focus. The camera focus is set to about halfway down the tracks. As you can see the f-stop has a big effect on the focus in the near and somewhat less effect on the distant building.
f/22 - All but a couple of inches closest to the camera are in sharp focus.
f/16 - the focus has moved several inches more down the track - the difference is quite noticeable already.
f/8 - the background scene is becoming defocused
f/5.6 - the Shell sign on the distant building is defocused
f/4.5 - all but a narrow band at the focal plane is defocused. Dramatic difference to the f/22 image!