The man travelled in different ways: by rail, by taxi, by ___ and by foot. I placed a blank there because there seems to be a missing word in the given problem above. For sample purposes, let's just assume that is travel by bus.
Since all of these travels are equal to 1 whole journey, you can express each travel as a fraction. When you add them up, the answer would be 1. So,
3/8 + 1/4 + 1/8 + x = 1
The variable x here denotes the fraction of his travel by foot. We are only given the exact distance travelled on foot which is 2 km. We have to find the fraction of the travel by foot to determine the length of the total distance travelled. Solving for x,
x = 1 - 3/8 - 1/4 - 1/8
x = 1/4
That means that the travel by foot comprises 1/4 of the whole journey. Thus,
Let total distance be D.
1.4*D = 2 km
D = 8 km
Therefore, the man travelled a total of 8 kilometers.