I had it in a rockery. It goes down so far that digging it out is not possible (apparently gravediggers find roots 6 ft down...) If you break off the black (wet-earth-coloured!!!) roots each one can root again. It likes damp places, but is not averse to any soil.
In the end I poured a driveway weedkiller over the whole rockery twice a year for about 5-6 years and left it bare. Then I eased off gardening because I had breast cancer and it filled up with weeds, buddleia seedlings - and marestail.
I got someone to strip out all the rocks, dig out the soil and replace the rocks and new topsoil. I replanted this spring and all was well until a few weeks ago, when the marestail started to peep up again. I have sprayed roundup into a plastic bag and tied it onto the stem, binding it all the way up, then bruised the stems with a stone. The concentrated sun through the plastic has wilted the marestail and it looks dead, but I am on the lookout for more shoots.
If you are alert in spring, you can sometimes catch out a fruiting stem, put up before any leaf stems appear. It is slim, about 6 ins high, has the characteristic joints, but is pale brown, not green, and the head is a brown and black oval - earth-coloured again and camouflaged. If you can get rid of this, at least you only have the established roots to deal with, not new plants.