2

I have the following code:

\documentclass[letterpaper]{article}

\usepackage{tikz}

\tikzset{ node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary. every node/.style={circle,thin, fill=black}, % sets the properties for each ’state’ node }

\begin{document}

Uma representação geométrica deste plano segue abaixo. \begin{figure}[H] \centering \begin{tikzpicture}[node distance = 3cm,
every node/.style={ circle, thin, inner sep = 2pt,fill, black!80 }, black!80 ] \node[label = {$1$}] (1) {}; \node[right of=1,label = {$2$}] (2) {}; \node[right of=2,label = {$3$}] (3) {}; \node[below of=1,label = left:{$4$}] (4) {}; \node[below of=2,label = {[label distance = .12cm]10:$5$}] (5) {}; \node[below of=3,label = right:{$6$}] (6) {}; \node[below of=4,label = below:{$7$}] (7) {}; \node[below of=5,label = below:{$8$}] (8) {}; \node[below of=6,label = below:{$9$}] (9) {}; \draw[-] (1) edge[asparagus] (2) (2) edge[asparagus] (3) (4) edge[red!80] (5) (5) edge[red!80] (6) (7) edge[purple] (8) (8) edge[purple] (9) (3) edge[orange!80] (5) (5) edge[orange!80] (7) (1) edge[gray] (5) (5) edge[gray] (9) (3) edge[bleudefrance!80] (6) (6) edge[bleudefrance!80] (9) (1) edge[cyan!80] (4) (4) edge[cyan!80] (7) (2) edge[pink] (5) (5) edge[pink] (8) (2) edge[dashed] (4) (4) edge[dashed, out=225, in=225, looseness=2] (9) (1) edge[orange!80,dashed, out=200, in=225,looseness=2.5] (8) (8) edge[orange!80,dashed] (6) (3) edge[purple,dashed, out=140, in = 140, looseness =2] (4) (4) edge[purple,dashed] (8) (6) edge[cyan,dashed] (2) (2) edge[cyan,dashed, out=140, in=140, looseness = 2.5] (7); \end{tikzpicture} \end{figure}

\end{document}

Which gives me the following output:

enter image description here

As it's visible in the output, there is way too much vertical space between the space and the figure. This also happens if I try to write after the figure, i.e., there is also a big vertical space if I add text after the figure. Is there a way to decrease this spacing?

David Carlisle
  • 757,742
Rodrigo
  • 491
  • 3
  • 9

2 Answers2

3
  • Your MWE is not compilable. Missed are definition of edge colors.
  • Try to use bbox library (available on CTAN):
\documentclass[letterpaper, ]{article}
\usepackage{tikz}
\usetikzlibrary{bbox}

\begin{document}

Uma representação geométrica deste plano segue abaixo. \begin{figure}[ht] \centering \begin{tikzpicture}[bezier bounding box, % <---- node distance = 22mm, start chain = right, dot/.style = {circle, thin, inner sep = 2pt, fill=black!80}, ] \begin{scope}[nodes={dot}] \node[label = {$1$}] (1) {}; \node[right of=1,label = {$2$}] (2) {}; \node[right of=2,label = {$3$}] (3) {}; \node[below of=1,label = left:{$4$}] (4) {}; \node[below of=2,label = {[label distance = .12cm]10:$5$}] (5) {}; \node[below of=3,label = right:{$6$}] (6) {}; \node[below of=4,label = below:{$7$}] (7) {}; \node[below of=5,label = below:{$8$}] (8) {}; \node[below of=6,label = below:{$9$}] (9) {}; \end{scope} \draw[-] (1) edge[asparagus] (2)
(2) edge[asparagus] (3)
(4) edge[red!80] (5) (5) edge[red!80] (6) (7) edge[purple] (8) (8) edge[purple] (9) (3) edge[orange!80] (5) (5) edge[orange!80] (7) (1) edge[gray] (5) (5) edge[gray] (9) (3) edge[bleudefrance!80] (6) (6) edge[bleudefrance!80] (9) (1) edge[cyan!80] (4) (4) edge[cyan!80] (7) (2) edge[pink] (5) (5) edge[pink] (8) (2) edge[dashed] (4) (4) edge[dashed, out=225, in=225, looseness=2] (9) (1) edge[orange!80,dashed, out=200, in=225,looseness=2.5] (8) (8) edge[orange!80,dashed] (6) (3) edge[purple,dashed, out=140, in = 140, looseness =2] (4) (4) edge[purple,dashed] (8) (6) edge[cyan,dashed] (2) (2) edge[cyan,dashed, out=140, in=140, looseness = 2.5] (7); \end{tikzpicture} \end{figure}

\end{document}

After forcing of compilation I get the following result:

enter image description here

Addendum:
Off-topic: an example of redesign of the OP image (as style as well of code). Changed are:

  • Positions of labels are defined labels anchors, which are the same for all nodes.
  • Lines between nodes are drawn in background.
  • Colors of lines are selected from default xcolor colors (it is loaded by tikz package). Now MWE can be compiled without warnings and errors.
  • Nodes are placed by use of chains library. This make code shorter and more clear.
\documentclass[letterpaper, ]{article}
\usepackage[a5paper,
            showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{backgrounds, 
                bbox,                        % <----
                chains,
                positioning}

\begin{document}

Uma representação geométrica deste plano segue abaixo. \begin{figure}[ht] \centering \begin{tikzpicture}[bezier bounding box, % <---- node distance = 22mm, start chain = right, dot/.style = {circle, thin, inner sep = 2pt, fill=black!80, on chain, label=#1, node contents={}, }, every label/.append style = {font=\small, fill=white, anchor=south west, inner sep=1.2pt, outer sep=1pt} ] \node (1) [dot = $1$]; \node (2) [dot = $2$]; \node (3) [dot = $3$];

\node (4) [dot = $4$, below=of 1]; \node (5) [dot = $5$]; \node (6) [dot = $6$];

\node (7) [dot = $7$, below=of 4]; \node (8) [dot = $8$]; \node (9) [dot = $9$];

\scoped[on background layer] \draw (1) edge[olive] (2) edge[olive] (3) % asparagus (4) edge[red!80] (5) edge[red!80] (6) (7) edge[purple] (8) edge[purple] (9) % (3) edge[orange!80] (5) edge[orange!80] (7) (1) edge[gray] (5) edge[gray] (9) % (1) edge[cyan!80] (4) edge[cyan!80] (7) (2) edge[pink] (5) edge[pink] (8) (3) edge[blue!80] (6) edge[blue!80] (9) % bleudefrance!80 ; \draw[orange!80,dashed] (6) to (8) edge[out=225, in=220,looseness=2.5] (1); \draw[dashed]
(2) to (4) edge[out=225, in=225, looseness=2] (9); \draw[cyan,dashed]
(6) to (2) edge[out=140, in=140, looseness=2.5] (7); \draw[purple!80,dashed] (8) to (4) edge[out=140, in=140, looseness=2] (3);

\end{tikzpicture} \end{figure} \end{document}

enter image description here

Zarko
  • 296,517
2

Use float package, like in this code:

\documentclass{article}
\usepackage{tikz,calc,lipsum,float}
\begin{document}
    \lipsum[1]
    \begin{figure}[H]
        \begin{tikzpicture}[scale=1.5]
            \draw[gray!30] (-3,-3) grid (3,3);
            \draw[-latex,blue] (-3.4,0)--(3.4,0) node[right] (x) {\footnotesize $x$};
            \draw[-latex,blue] (0,-3.4)--(0,3.4) node[above] (y) {\footnotesize $y$};
            \foreach \i in {-3,-2,...,3}{
                \foreach \j in {-3,-2,...,3}{
                    %\pgfmathsetmacro\h{int(\i+\j)};
                    \filldraw[black] (\i,\j) circle(.8pt);
                    \node[blue,right] at (\i,\j+.1) (\i) {\tiny (\i,\j)};
            }
        } 
    \end{tikzpicture}  
\caption{Tikzpcture below text}
\end{figure}
\lipsum[2]   

\end{document}

Output:

enter image description here