If you and your local scout troop go all together on a hike, you may be altogether tired when you get back. As this example shows, altogether and all together do not mean the same thing. We use all together to indicate that the members of a group perform or undergo an action collectively: The nations stood all together. The prisoners were herded all together. We use all together only in sentences that can be rephrased so that all and together may be separated by other words. Thus you can tell that all together is correct in the sentence The books lay all together in a heap since you can rephrase it as All the books lay together in a heap.
1
The adverb altogether, on the other hand, has several different meanings. Its easy to see how confusion might arise with the phrase all together when we use altogether to mean all told, in all: Altogether, there were fifty people at the wedding. Most frequently, however, we use altogether as a synonym for entirely or completely: The researchers tried an altogether different approach this time. But we can also use it as a sentence adverb meaning with everything considered, on the whole: Altogether, I can understand why she took offense.