居中組圖

居中組圖

誰能告訴我如何將其居中group plot?我已經嘗試了 tex.stackexchange 書中類似帖子中的所有技巧(例如,如何在 LaTeX 中將大數字居中以及如何修復短對齊線?)。

\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}

答案1

你的地塊太寬了。您可以嘗試將 2 個圖排成一行,而不是 3 個。

\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}

在此輸入影像描述

如果以防萬一,您想要將最後兩個圖居中,您可以為所有圖使用合適的寬度(以便您知道要移動多少)並使用xshift類似

\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 {
        };

在此輸入影像描述

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}

        \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};

在此輸入影像描述

答案2

另一種選擇:新增\hspace*{-4cm}(調整您想要實現良好居中的公分數)。例如:

\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}

在此輸入影像描述

相關內容