我怎样才能使 tikzpicture 居中?

我怎样才能使 tikzpicture 居中?

我正在寻找将以下 tikzpicture 置于页面中心的方法(我使用的是 Overleaf)。但是我无法实现,它显示移动到了右侧部分...有什么想法吗?

\documentclass{article}
    \usepackage{tikz}
    \centering
    \usetikzlibrary{arrows.meta}
    \begin{document}
    \begin{minipage}[c]{1.7\textwidth}
    \centering
    \begin{center}
    \begin{tikzpicture}
        \begin{scope}[every node/.style={circle,thick,draw}]
            \node (A) at (-12,-2)  {N5xx};
            \node (B) at (-10,4)   {N612};
            \node (C) at (-5,7)    {N614};
            \node (D) at (0,4)     {N624};
            \node (E) at (2,-2)    {N7070};
            \node (F) at (-1,-8)   {N7071};
            \node (G) at (-9,-8)   {Others};
        \end{scope}

        \begin{scope}[>={Stealth[black]},
                    center coordinate every node/.style={fill=white,circle},
                     % every edge/.style={draw=red,very thick}
                     ]
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$5$}  (B);
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$3$}  (C);
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$4$}  (D);
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$3$}  (E);
            \path [->] (A) edge[bend right = 25, blue,very thick]  node {$3$}  (F);
            \path [->] (A) edge[bend right = 25, blue,very thick]  node {$3$}  (G);
            \path [->] (A) edge[loop left = 25, blue,very thick]   node {$3$}  (A);

            \path [->] (B) edge[loop left = 15, red,very thick]   node {$5$}  (B);
            \path [->] (B) edge[bend right = 25, red,very thick]   node {$3$}  (A);
            \path [->] (B) edge[bend left = 15, red,very thick]   node {$3$}  (C);
            \path [->] (B) edge[bend left = 15, red,very thick]   node {$4$}  (D);
            \path [->] (B) edge[bend left = 15, red,very thick]   node {$3$}  (E);
            \path [->] (B) edge[bend right = 25, red,very thick]  node {$3$}  (F);
            \path [->] (B) edge[bend right = 25, red,very thick]  node {$3$}  (G);

            \path [->] (C) edge[green,very thick]   node {$3$}  (A);
            \path [->] (C) edge[bend right = 30, green,very thick]   node {$5$} (B);
            \path [->] (C) edge[loop above = 15, green,very thick]  node {$3$}  (C);
            \path [->] (C) edge[bend left = 30, green,very thick]   node {$4$}  (D);
            \path [->] (C) edge[ green,very thick]   node {$3$}  (E);
            \path [->] (C) edge[bend left = 5, green,very thick]  node {$3$}  (F);
            \path [->] (C) edge[bend right = 5, green,very thick]  node {$3$}   (G);

            \path [->] (D) edge[bend left = 25, orange,very thick]    node {$3$}  (A);
            \path [->] (D) edge[bend left = 15, orange,very thick]    node {$5$}  (B);
            \path [->] (D) edge[bend right = 15,orange,very thick]   node {$3$}  (C);
            \path [->] (D) edge[loop right = 15,orange,very thick]   node {$4$}  (D);
            \path [->] (D) edge[bend left = 15, orange,very thick]    node {$3$}  (E);
            \path [->] (D) edge[bend left = 25,orange,very thick]   node {$3$}  (F);
            \path [->] (D) edge[bend left = 25,orange,very thick]   node {$3$}  (G);

            \path [->]  (E) edge[bend left = 25, purple!50 ,very thick]    node {$3$}  (A);
            \path [->]  (E) edge[bend left = 15, purple!50,very thick]    node {$5$}  (B);
            \path [->]  (E) edge[bend right = 15,purple!50,very thick]    node {$3$}  (C);
            \path [->]  (E) edge[bend right = 15,purple!50,very thick]    node {$4$}  (D);
            \path [->]  (E) edge[loop right = 15, purple!50,very thick]    node {$3$}  (E);
            \path [->]  (E) edge[bend left = 25,purple!50,very thick]     node {$3$}  (F);
            \path [->]  (E) edge[bend left = 25,purple!50,very thick]     node {$3$}  (G);

             \path [->]  (F) edge[bend left = 25, very thick]    node {$3$}  (A);
            \path [->]  (F) edge[bend left = 15, very thick]    node {$5$}  (B);
            \path [->]  (F) edge[bend right = 15,very thick]    node {$3$}  (C);
            \path [->]  (F) edge[bend right = 15, very thick]    node {$4$}  (D);
            \path [->]  (F) edge[bend right = 15, very thick]    node {$3$}  (E);
            \path [->]  (F) edge[loop right = 25,very thick]     node {$3$}  (F);
            \path [->]  (F) edge[bend left = 25,very thick]     node {$3$}  (G);


        \end{scope}

        \end{tikzpicture}
    \end{center}



        \end{minipage}
     \end{document}

答案1

首先,我将minipage宽度改为1\textwidth,而不是1.7\textwidth。然后,我删除了center环境,因为它基本上与 重复\centering。然后我将图像放在 中\makebox[0pt]{},这样边距违规就会被忽略。我\par在末尾添加了 ,只是为了强调\centering需要段落结束才能生效。

\documentclass{article}
    \usepackage{tikz}
    \centering
    \usetikzlibrary{arrows.meta}
    \begin{document}
    \begin{minipage}[c]{1\textwidth}
    \centering
    \makebox[0pt]{%
    \begin{tikzpicture}
        \begin{scope}[every node/.style={circle,thick,draw}]
            \node (A) at (-12,-2)  {N5xx};
            \node (B) at (-10,4)   {N612};
            \node (C) at (-5,7)    {N614};
            \node (D) at (0,4)     {N624};
            \node (E) at (2,-2)    {N7070};
            \node (F) at (-1,-8)   {N7071};
            \node (G) at (-9,-8)   {Others};
        \end{scope}

        \begin{scope}[>={Stealth[black]},
                    center coordinate every node/.style={fill=white,circle},
                     % every edge/.style={draw=red,very thick}
                     ]
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$5$}  (B);
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$3$}  (C);
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$4$}  (D);
            \path [->] (A) edge[bend left = 15, blue,very thick]   node {$3$}  (E);
            \path [->] (A) edge[bend right = 25, blue,very thick]  node {$3$}  (F);
            \path [->] (A) edge[bend right = 25, blue,very thick]  node {$3$}  (G);
            \path [->] (A) edge[loop left = 25, blue,very thick]   node {$3$}  (A);

            \path [->] (B) edge[loop left = 15, red,very thick]   node {$5$}  (B);
            \path [->] (B) edge[bend right = 25, red,very thick]   node {$3$}  (A);
            \path [->] (B) edge[bend left = 15, red,very thick]   node {$3$}  (C);
            \path [->] (B) edge[bend left = 15, red,very thick]   node {$4$}  (D);
            \path [->] (B) edge[bend left = 15, red,very thick]   node {$3$}  (E);
            \path [->] (B) edge[bend right = 25, red,very thick]  node {$3$}  (F);
            \path [->] (B) edge[bend right = 25, red,very thick]  node {$3$}  (G);

            \path [->] (C) edge[green,very thick]   node {$3$}  (A);
            \path [->] (C) edge[bend right = 30, green,very thick]   node {$5$} (B);
            \path [->] (C) edge[loop above = 15, green,very thick]  node {$3$}  (C);
            \path [->] (C) edge[bend left = 30, green,very thick]   node {$4$}  (D);
            \path [->] (C) edge[ green,very thick]   node {$3$}  (E);
            \path [->] (C) edge[bend left = 5, green,very thick]  node {$3$}  (F);
            \path [->] (C) edge[bend right = 5, green,very thick]  node {$3$}   (G);

            \path [->] (D) edge[bend left = 25, orange,very thick]    node {$3$}  (A);
            \path [->] (D) edge[bend left = 15, orange,very thick]    node {$5$}  (B);
            \path [->] (D) edge[bend right = 15,orange,very thick]   node {$3$}  (C);
            \path [->] (D) edge[loop right = 15,orange,very thick]   node {$4$}  (D);
            \path [->] (D) edge[bend left = 15, orange,very thick]    node {$3$}  (E);
            \path [->] (D) edge[bend left = 25,orange,very thick]   node {$3$}  (F);
            \path [->] (D) edge[bend left = 25,orange,very thick]   node {$3$}  (G);

            \path [->]  (E) edge[bend left = 25, purple!50 ,very thick]    node {$3$}  (A);
            \path [->]  (E) edge[bend left = 15, purple!50,very thick]    node {$5$}  (B);
            \path [->]  (E) edge[bend right = 15,purple!50,very thick]    node {$3$}  (C);
            \path [->]  (E) edge[bend right = 15,purple!50,very thick]    node {$4$}  (D);
            \path [->]  (E) edge[loop right = 15, purple!50,very thick]    node {$3$}  (E);
            \path [->]  (E) edge[bend left = 25,purple!50,very thick]     node {$3$}  (F);
            \path [->]  (E) edge[bend left = 25,purple!50,very thick]     node {$3$}  (G);

             \path [->]  (F) edge[bend left = 25, very thick]    node {$3$}  (A);
            \path [->]  (F) edge[bend left = 15, very thick]    node {$5$}  (B);
            \path [->]  (F) edge[bend right = 15,very thick]    node {$3$}  (C);
            \path [->]  (F) edge[bend right = 15, very thick]    node {$4$}  (D);
            \path [->]  (F) edge[bend right = 15, very thick]    node {$3$}  (E);
            \path [->]  (F) edge[loop right = 25,very thick]     node {$3$}  (F);
            \path [->]  (F) edge[bend left = 25,very thick]     node {$3$}  (G);


        \end{scope}

        \end{tikzpicture}%
    }\par



        \end{minipage}
     \end{document}

在此处输入图片描述

相关内容