TikZ 中的移动图表:中心不工作

TikZ 中的移动图表:中心不工作

我无法使图表对齐tikzpicture。目前,如果我使用“\centering”,我的网络图会移动到 pdf 的右侧。如果我不这样做,它就会移动到 pdf 的左侧。我该如何让它居中?谢谢

\documentclass[fleqn]{article}
\usepackage{amsmath,amsthm,amssymb,sgame,color,fullpage,tikz,caption,subcaption}
\usetikzlibrary{arrows}
\newtheorem{prop}{Proposition}
\theoremstyle{definition}
\newtheorem{mydef}{Definition}
\newtheorem{observation}{Observation}
\newtheorem{assumpt}{Assumption}
\newtheorem{remark}{Remark}
\newtheorem{lemma}{Lemma}
\newtheorem{e.g.}{Example}


\begin{document}

\begin{figure*}[t!]
\centering
          \begin{tabular} {lp{3cm}} &
\begin{tikzpicture} [shorten >=1pt,auto,node distance=2cm,
                    thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}, ]

  \node[main node] (1) {$m_{12}$};
  \node[main node] (2) [left of=1] {$w_{11}$};
  \node[main node] (3) [ below of=1] {$m_{22}$};
  \node[main node] (4) [right of=1] {$w_{12}$};
    \node[main node] (5) [right of=4]   {$m_{13}$};
  \node[main node] (6) [below of=5] {$m_{23}$};
  \node[main node] (7) [ below of=6] {$m_{33}$};
  \node[main node] (8) [right of=5] {$w_{13}$};



\draw
 (1) --  (4)
 (3) --  (4)
 (5) --  (8)
 (6) --  (8)
 (7) --  (8);




\end{tikzpicture}
\captionof{figure}{Initial $\bar{g}$}
\label{tikz}
\end{tabular}



\end{figure*}

答案1

您不需要环境tabular。删除以下两行:

\begin{tabular} {lp{3cm}} &
.
.
.
\end{tabular}

来自您的代码。另外,由于您将图片放在环境tikz中(为什么不使用),因此您不需要使用但。figure*figure\captionofcaption

\documentclass[fleqn]{article}
\usepackage{amsmath,amsthm,amssymb,sgame,color,fullpage,tikz,caption,subcaption}
\usetikzlibrary{arrows}


\begin{document}

\begin{figure*}[t!]
\centering
%          \begin{tabular} {lp{3cm}} &
\begin{tikzpicture} [shorten >=1pt,auto,node distance=2cm,
                    thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}, ]

  \node[main node] (1) {$m_{12}$};
  \node[main node] (2) [left of=1] {$w_{11}$};
  \node[main node] (3) [ below of=1] {$m_{22}$};
  \node[main node] (4) [right of=1] {$w_{12}$};
    \node[main node] (5) [right of=4]   {$m_{13}$};
  \node[main node] (6) [below of=5] {$m_{23}$};
  \node[main node] (7) [ below of=6] {$m_{33}$};
  \node[main node] (8) [right of=5] {$w_{13}$};



\draw
 (1) --  (4)
 (3) --  (4)
 (5) --  (8)
 (6) --  (8)
 (7) --  (8);
\end{tikzpicture}
\caption{Initial $\bar{g}$}
\label{tikz}
%\end{tabular}



\end{figure*}
\end{document}

在此处输入图片描述

相关内容