Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I tried to use groupplots to arrange several bar plots but the titles are drawn on top of the axis labels of the plot above. Am I doing something wrong here?

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}
  \begin{tikzpicture}
    \begin{groupplot}[group style={group size=2 by 2},width=0.45\textwidth,ybar]
      \nextgroupplot[title=title 1-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 1-2]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-2]
        \addplot coordinates { (1,1) (42,23)};
    \end{groupplot}
  \end{tikzpicture}
\end{document}

Titles of sub plots

Edit: maybe I should also mention why I'm specifically asking for ybar plots. I tried the same example without the ybar and the spacing was different. The title fits below the axis label without this option but the spacing still looked off. Anyway, I need bar plots so I cannot remove this option.

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

Use the vertical sep=<length> option to increase the vertical spacing:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}
  \begin{tikzpicture}
    \begin{groupplot}[group style={group size=2 by 2,vertical sep= 1.5cm},width=0.45\textwidth,ybar]
      \nextgroupplot[title=title 1-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 1-2]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-1]
        \addplot coordinates { (1,1) (42,23)};
      \nextgroupplot[title=title 2-2]
        \addplot coordinates { (1,1) (42,23)};
    \end{groupplot}
  \end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

No you have done it right, however at the moment it does not autocompute the distance required for nice spacing. You can play with the option:

vertical sep=<latex length>

to get the right spacing between them.

share|improve this answer
add comment

Your Answer

 
discard

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.