4

Can anyone show me how to center this group plot? I've tried every trick in the tex.stackexchange book of similar posts (e.g., How to center large figures in LaTeX and how to fix short justified lines?).

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}
    \begin{tikzpicture}[font=\footnotesize\sffamily]
      \begin{groupplot}[
         group style={group size=3 by 2, vertical sep=70pt,
    ylabels at=edge left
    },
          view={0}{90},
          width=5.2cm,
          height=5.2cm,
      scale only axis,
      scaled ticks = false,
      tick label style={/pgf/number format/fixed},
      title={My title},
      xlabel={x-axis},
      ylabel={y-axis}],
          unbounded coords=jump]
        ]
        \nextgroupplot [title={\it{Title 1}}]       
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 2}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 3}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 4}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 5}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

         \end{groupplot}

    \end{tikzpicture}
  \end{figure}



\end{document}
5

Your plots are too wide. You may try to put 2 plots in a row instead of 3. However, there is always this box techniques that can be used.

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}
\makebox[\textwidth]{%
    \begin{tikzpicture}[font=\footnotesize\sffamily]
      \begin{groupplot}[
         group style={group size=3 by 2, vertical sep=70pt,
    ylabels at=edge left
    },
          view={0}{90},
          width=5.2cm,
          height=5.2cm,
      scale only axis,
      scaled ticks = false,
      tick label style={/pgf/number format/fixed},
      title={My title},
      xlabel={x-axis},
      ylabel={y-axis}],
          unbounded coords=jump]
        ]
        \nextgroupplot [title={\it{Title 1}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 2}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 3}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

         \end{groupplot}

    \end{tikzpicture}
    }
  \end{figure}




\end{document}

enter image description here

If in case, you want to center the last two plots, you may use a suitable width for all plots (so that you know how much to shift) and use xshift like

\nextgroupplot [xshift=1.2in,title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [xshift=1.2in,title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

enter image description here

With table:

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}
\usepackage{filecontents}
 \begin{filecontents*}{mydata.dat}
  A   B      
  1    4
  2    6
  3    9
  4    2
  5    3
  \end{filecontents*}

\begin{document}

\begin{figure}
\makebox[\textwidth]{%
    \begin{tikzpicture}[font=\footnotesize\sffamily]
      \begin{groupplot}[
         group style={group size=3 by 2, vertical sep=70pt,
    ylabels at=edge left
    },
          view={0}{90},
          width=5.2cm,
          height=5.2cm,
      scale only axis,
      scaled ticks = false,
      tick label style={/pgf/number format/fixed},
      title={My title},
      xlabel={x-axis},
      ylabel={y-axis}],
          unbounded coords=jump]
        ]
        \nextgroupplot [title={\it{Title 1}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 2}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 3}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

         \end{groupplot}

    \end{tikzpicture}
    }
  \end{figure}




\end{document}

and with

        \nextgroupplot [xshift=1.2in,title={\it{Title 4}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

        \nextgroupplot [xshift=1.2in,title={\it{Title 5}}]
\addplot[black, thick, mark=o, only marks]
    table[x=A,y=B]{mydata.dat};

enter image description here

  • Can you please show how to use the table environment in place of coordinates? For some reason, this code does not work (yet) with table {} Please just add a new section to your answer, do not delete anything you have written, it is very useful. – warship Apr 24 '15 at 5:36
  • @warship Certainly, see the update. – user11232 Apr 24 '15 at 11:10
0

Another alternative: add \hspace*{-4cm} (adjust how many centimeters you want to achieve a nice centering). For example:

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}
\hspace*{-4cm}
    \begin{tikzpicture}[font=\footnotesize\sffamily]
      \begin{groupplot}[
         group style={group size=3 by 2, vertical sep=70pt,
    ylabels at=edge left
    },
          view={0}{90},
          width=5.2cm,
          height=5.2cm,
      scale only axis,
      scaled ticks = false,
      tick label style={/pgf/number format/fixed},
      title={My title},
      xlabel={x-axis},
      ylabel={y-axis}],
          unbounded coords=jump]
        ]
        \nextgroupplot [title={\it{Title 1}}]       
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 2}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 3}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 4}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

        \nextgroupplot [title={\it{Title 5}}]      
\addplot[black, thick, mark=o, only marks]
    coordinates {
        };

         \end{groupplot}

    \end{tikzpicture}
  \end{figure}



\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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