4

As title states, I simply want my TikZ picture to be placed next to my table.

I don't mind whether the captions are separate or together.

Below is my code.

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.9]
\begin{pgfonlayer}{nodelayer}
    \node [style=station] (0) at (-2, 3) [label=left:E] {};
    \node [style=station] (1) at (2, 3) [label=right:B]{};
    \node [style=station] (2) at (-1.25, 0.75)[label=left:D] {};
    \node [style=station] (3) at (1.25, 0.75) [label=right:C]{};
    \node [style=station] (4) at (0, 4.5) [label=above: A]{};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
    \draw [style=edge] (0) to (4);
    \draw [style=edge] (4) to (1);
    \draw [style=edge] (1) to (3);
    \draw [style=edge] (0) to (2);
    \draw [style=edge] (3) to (2);
    \draw [style=edge] (2) to (4);
    \draw [style=edge] (4) to (3);
    \draw [style=edge] (0) to (1);
    \draw [style=edge] (0) to (3);
    \draw [style=edge] (2) to (1);
\end{pgfonlayer}
\end{tikzpicture}
\caption{Weighted, complete graph $K_H$}
\end{figure}
\begin{table}[h]
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{c|ccccc}
 & A  & B & C & D & E  \\
\hline
A & --  & 4 & 7 & 6 & 12 \\ 
B & 4  & -- & 3 & 5 & 8  \\
C & 7  & 3 & -- & 2 & 5  \\
D & 6  & 5 & 2 & -- & 9  \\
E & 12 & 8 & 5 & 9 & -- 
\end{tabular}
\caption{Weights of edges in graph $K_H$}
\end{table}
CarLaTeX
  • 62,716

1 Answers1

3

i guess what you like to draw ... however, this should be close to your intention:

enter image description here

since you not provide complete document, i didn't bother with code of yours image (it can be further improved).

  • to have figure and table in parallel, you had to have in the same floating environment
  • for their captions you should use \captionof{table}{...} which is defined in the packages caption or capt-of
  • for positioning in paralel you can use minipage or table as is done n mwe below

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{automata,shapes.geometric}
\usepackage{array}
\usepackage[font=footnotesize, labelfont=bf]{caption}

\usepackage[active,floats,tightpage]{preview}
    \setlength\PreviewBorder{1em}


    \begin{document}
%---------------------------------------------------------------%
\begin{figure}[h]
\begin{tabular}{*{2}{>{\centering\arraybackslash}b{\dimexpr0.5\linewidth-2\tabcolsep\relax}}}
\begin{tikzpicture}[
state/.append style={minimum size=5mm}]
%\begin{pgfonlayer}{nodelayer}
    \node [state] (0) at (-2, 3) [label=left:E] {};
    \node [state] (1) at ( 2, 3) [label=right:B]{};
    \node [state] (2) at (-1.25, 0.75)[label=left:D] {};
    \node [state] (3) at ( 1.25, 0.75) [label=right:C]{};
    \node [state] (4) at ( 0, 4.5) [label=above: A]{};
%\end{pgfonlayer}
%\begin{pgfonlayer}{edgelayer}
    \draw  (0) to (4);
    \draw (4) to (1);
    \draw (1) to (3);
    \draw (0) to (2);
    \draw (3) to (2);
    \draw (2) to (4);
    \draw (4) to (3);
    \draw (0) to (1);
    \draw (0) to (3);
    \draw (2) to (1);
%\end{pgfonlayer}
\end{tikzpicture}
\caption{Weighted, complete graph $K_H$}
    &
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{c|ccccc}
 & A  & B & C & D & E  \\
\hline
A & --  & 4 & 7 & 6 & 12 \\
B & 4  & -- & 3 & 5 & 8  \\
C & 7  & 3 & -- & 2 & 5  \\
D & 6  & 5 & 2 & -- & 9  \\
E & 12 & 8 & 5 & 9 & --
\end{tabular}
\captionof{table}{Weights of edges in graph $K_H$}
\end{tabular}
\end{figure}
%---------------------------------------------------------------%
    \end{document}
Zarko
  • 296,517