TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to have two subplots with the same x axis aligned above one another. In the manual I read, that I should use \matrix{} to achieve this.

Now I want to have legends in both plots. But since the legend box itself seems to use the matrix environment, this gives me the error "You cannot nest pgfmatrix environments, yet."

Here is a reduced example of what does not work:

        \addplot {x} ;

Any ideas?

share|improve this question
up vote 5 down vote accepted

This is a known limitation of TikZ matrizes - and of pgfplots legends in such a context as well.

There are a couple of possible alternatives to solve the problem:

  1. to detach the legend and place it (say) below your array of subplots

  2. to use a LaTeX table for the array alignment

  3. groupplots (but only if the involved axes share a common axis).

The details along with a lot of examples have been documented in the pgfplots manual http://pgfplots.sourceforge.net/pgfplots.pdf (perhaps your version of the manual belongs to an older version in which this section is not up to date).

share|improve this answer
Thank you (also for pgfplots itself). I always assumed that the height and width of all plots within a groupplot must be the same. – Tim Aug 17 '12 at 10:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.