1

I have a few pictures where the box around them is too big. The code below is an example. In this case the figure goes too far to the right. Can anyone help me get these under control?

\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}
ThomasC
  • 161
  • The diagrams or the box? You have two minipages each with width 0.5\textwidth, so naturally the \tcbox becomes wider than \textwidth in total. – Torbjørn T. Dec 05 '17 at 11:07
  • Note that \tcbox{ followed by a line break can add a space which moves the content to the right. TeX does take line breaks as spaces. To avoid this add a % to ignore the line break: \tcbox{%. – Martin Scharrer Dec 05 '17 at 11:30
  • If you want to scale and center boxed content check out the adjustbox package. – Martin Scharrer Dec 05 '17 at 11:31

1 Answers1

5

Presumably this is what you were after?

output of code

The extra space in the box in your case came from the minipage environments, that were wider than the tikzpictures, and thus created a lot of extra space. But from what you show in your code, there is no reason to use minipages here, so I'd just remove them. You can add some horizontal space between the diagrams with \hspace, if needed.

Note also that centering is not actually an environment, it is a macro that should be used as \centering, which affects the text that follows it in the same group. There is an environment called center, but that adds some vertical space, and is usually not recommended inside a figure, cf. Should I use center or centering for figures and tables?

\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}
Torbjørn T.
  • 206,688