0

This code

\documentclas{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{figure} \centering \resizebox{.5\textwidth}{!}{ \fbox{ \begin{tikzpicture}[main/.style = {draw, circle}]

    \node[main] (1) {$1$};
    \node[main] (2) [above of=1] {$2$};
    \node[main] (3) [right of=1] {$3$};
    \node[main] (4) [right of=2] {$4$};
    \node[main] (5) [right of=3] {$5$};
    \node[main] (6) [right of=4] {$6$};

    \draw[->] (1) edge node[midway, above, sloped] {\tiny 1} (2);
    \draw[->] (2) edge node[midway, below, sloped] {\tiny 1-$\epsilon$} (3);
    \draw[->] (2) edge node[midway, above, sloped] {\tiny 1} (4);
    \draw[->] (3) edge node[midway, above, sloped] {\tiny 1} (4);
    \draw[->] (4) edge node[midway, below, sloped] {\tiny 1-$\epsilon$} (5);
    \draw[->] (4) edge node[midway, above, sloped] {\tiny 1} (6);
    \draw[<->] (6) edge node[midway, above, sloped] {\tiny 1} (5);
    \draw[->] (5) edge node[midway, below, sloped] {\tiny 1} (3);
    \draw[->] (3) edge node[midway, below, sloped] {\tiny 1}(1);
    \path[->] (6)  edge[bend left=90, out=150, looseness = 2] node[midway, below, sloped] {\tiny 100} (1);
\end{tikzpicture} }
}

\caption{An example of nearest neighbor working poorly} \label{tikz:NN_bad_sol} \end{figure}

\end{document}

Yields this output

Output

From what I could figure out, the problem is being caused by the last path. If I remove it, the picture is centered and has no whitespace. I don't understand how edge 6 -> 1 is creating so much whitespace

  • 1
    What creates this empty space is the bent curve, because it uses control points that are far away from the curve, hence the space. You should clip your picture to avoid that. On a side note, there's no \begin{document} in your code. – SebGlav Jan 19 '23 at 18:47
  • Thank you, @SebGlav, I wasn't aware of control points, your suggestion works perfectly. As for the side note, you are right, the MWE wasn't working very well :) – J. Dionisio Jan 19 '23 at 18:53
  • 1
    Just add \clip (-1,-1) rectangle (3.5,1.8); on the beginning of your tikzpicture. – SebGlav Jan 19 '23 at 18:54
  • See https://tex.stackexchange.com/questions/665769/how-to-reduce-vertical-space-between-text-and-a-figure-that-contains-tikzpicture/665770#665770 . Package bbox contain good explanation about problem you discussed in question – Zarko Jan 19 '23 at 19:17

0 Answers0