5

I am trying to use TikZ to include a simple graph in a short document, but I can't get to position the image properly. Sorry if it is a bit stupid, but this is the first time I am doing something like this.

Here is the code:

\documentclass[12pt]{article}
\usepackage[czech]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usepackage{amsmath}
\tikzstyle{vertex}=[auto=left,circle,fill=black!25,minimum size=20pt,inner sep=0pt]

\begin{document}
\raggedright
  Jméno: Alexandar Živkovič\\
  UČO: 325003\\
  \bigskip
  \begin{enumerate}
    \item %1)
      \pagebreak
    \item %2)
  Graf:\bigskip
  \begin{tikzpicture}
  \node[vertex] (n1) at (3,3)  {1};
  \node[vertex] (n2) at (6,3)  {2};
  \node[vertex] (n3) at (7, 1) {3};
  \node[vertex] (n4) at (6, -1) {4};
  \node[vertex] (n5) at (3, -1) {5};
  \node[vertex] (n6) at (2, 1) {6};

  \foreach \from/\to in {n1/n2,n1/n3,n1/n5,n2/n1,n2/n3,n2/n4,n2/n5,n2/n6,n3/n1,n3/n2,n3/n5,n3/n6,n4/n2,n4/n5,n4/n6,n5/n1,n5/n2,n5/n3,n5/n4,n5/n6,n6/n2,n6/n3,n6/n4,n6/n5}
  \draw (\from) -- (\to);

  \end{tikzpicture}

  Počet sledů z vrcholu $1$ do vrcholu $6$ délky $5$:\smallskip

  \item %3)

  \end{enumerate}
  \end{document}

Any help is welcome.

Moriambar
  • 11,466

2 Answers2

5

Simply add a \par after Graf:. bigksip only takes effect at the next paragraph. With

Graf:\par\bigskip

we obtain the desired result:

enter image description here

As @Frédéric suggested \begin{center}...\end{center} around the tikzpicture will work. However, this will have additional vertical space as per Should I use center or centering for figures and tables? and When should we use \begin{center} instead of \centering?. Alternatively, you could use

\begin{figure}[h]\centering
\begin{tikzpicture}
 ...
\end{tikzpicture}
\end{figure}
Peter Grill
  • 223,288
3

A simple and effective solution is to wrap the picture within \begin{center}and \end{center} . This will place it in the center, on the next line.

\documentclass[12pt]{article}
\usepackage[czech]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usepackage{amsmath}
\tikzstyle{vertex}=[auto=left,circle,fill=black!25,minimum size=20pt,inner sep=0pt]

\begin{document}
\raggedright
  Jméno: Alexandar Živkovič\\
  UČO: 325003\\
  \bigskip
  \begin{enumerate}
    \item %1)
      \pagebreak
    \item %2)
  Graf:
  \begin{center}
  \begin{tikzpicture}
  \node[vertex] (n1) at (3,3)  {1};
  \node[vertex] (n2) at (6,3)  {2};
  \node[vertex] (n3) at (7, 1) {3};
  \node[vertex] (n4) at (6, -1) {4};
  \node[vertex] (n5) at (3, -1) {5};
  \node[vertex] (n6) at (2, 1) {6};

  \foreach \from/\to in {n1/n2,n1/n3,n1/n5,n2/n1,n2/n3,n2/n4,n2/n5,n2/n6,n3/n1,n3/n2,n3/n5,n3/n6,n4/n2,n4/n5,n4/n6,n5/n1,n5/n2,n5/n3,n5/n4,n5/n6,n6/n2,n6/n3,n6/n4,n6/n5}
  \draw (\from) -- (\to);

  \end{tikzpicture}
  \end{center}

  Počet sledů z vrcholu $1$ do vrcholu $6$ délky $5$:\smallskip

  \item %3)

  \end{enumerate}
  \end{document}
Moriambar
  • 11,466
Frédéric
  • 11,087
  • 3
  • 37
  • 43