为什么这张图片向右溢出太多了?

为什么这张图片向右溢出太多了?

我有一些图片,它们周围的框太大了。下面的代码就是一个例子。在这种情况下,图形太靠右了。有人能帮我控制一下吗?

\begin{figure}
\begin{centering}
\tcbox{
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}
\node (F1) at (0,0) [draw, shape=circle] {F1};
\node (B1) at (0,2.5) [draw, shape=circle] {B1};
\node (B2) at (2.5,2.5) [draw, shape=circle] {B2};
\node (F2) at (2.5,0) [draw, shape=circle] {F2};
\node (F3) at (2.5,-2.5) [draw, shape=circle] {F3};
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {2} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {3} (B2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[above left] {6} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {1} (F2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[right] {1} (B2);
\draw [-{Stealth[scale=3.0]}] (F3) -- node[right] {1} (F2);
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}
\node (F1) at (0,0) [draw, shape=circle] {F1};
\node (B1) at (0,2.5) [draw, shape=circle] {B1};
\node (B2) at (2.5,2.5) [draw, shape=circle] {B2};
\node (F2) at (2.5,0) [draw, shape=circle] {F2};
\node (F3) at (2.5,-2.5) [draw, shape=circle] {F3};
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {2} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {7} (B2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[above left] {6} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {1} (F2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[right] {3} (B2);
\draw [-{Stealth[scale=3.0]}] (F3) -- node[right] {1} (F2);
\end{tikzpicture}
\end{minipage}%
}
\end{centering}
\end{figure}

答案1

想必这就是您所追求的?

代码输出

在您的案例中,框中的额外空间来自minipage比 s 更宽的环境,因此创建了大量额外空间。但从您在代码中显示的内容来看,这里没有理由使用 minipages,所以我会删除它们。如果需要,tikzpicture您可以使用 在图表之间添加一些水平空间。\hspace

还要注意,这centering实际上不是一个环境,而是一个应该用作的宏\centering,它会影响同一组中其后的文本。有一个名为的环境center,但它会增加一些垂直空间,通常不建议在里面使用figure,参见。我应该对图形和表格使用 center 还是 centering ?

\documentclass{article}
\usepackage{tcolorbox,tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}
\centering
\tcbox{
\begin{tikzpicture}
\node (F1) at (0,0) [draw, shape=circle] {F1};
\node (B1) at (0,2.5) [draw, shape=circle] {B1};
\node (B2) at (2.5,2.5) [draw, shape=circle] {B2};
\node (F2) at (2.5,0) [draw, shape=circle] {F2};
\node (F3) at (2.5,-2.5) [draw, shape=circle] {F3};
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {2} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {3} (B2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[above left] {6} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {1} (F2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[right] {1} (B2);
\draw [-{Stealth[scale=3.0]}] (F3) -- node[right] {1} (F2);
\end{tikzpicture}\hspace{1cm}
\begin{tikzpicture}
\node (F1) at (0,0) [draw, shape=circle] {F1};
\node (B1) at (0,2.5) [draw, shape=circle] {B1};
\node (B2) at (2.5,2.5) [draw, shape=circle] {B2};
\node (F2) at (2.5,0) [draw, shape=circle] {F2};
\node (F3) at (2.5,-2.5) [draw, shape=circle] {F3};
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {2} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {7} (B2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[above left] {6} (B1);
\draw [-{Stealth[scale=3.0]}] (F1) -- node[below left] {1} (F2);
\draw [-{Stealth[scale=3.0]}] (F2) -- node[right] {3} (B2);
\draw [-{Stealth[scale=3.0]}] (F3) -- node[right] {1} (F2);
\end{tikzpicture}
}
\end{figure}

\end{document}

相关内容