将 Tikz 图片和表格并排放置

将 Tikz 图片和表格并排放置

正如标题所述,我只是想将我的 TikZ 图片放在我的桌子旁边。

我不介意字幕是分开的还是连在一起的。

下面是我的代码。

\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}

答案1

我猜你喜欢画什么......不过,这应该接近你的意图:

在此处输入图片描述

由于您没有提供完整的文档,所以我没有理会您的图像代码(它可以进一步改进)。

  • 要使图形和表格并行,你必须在同一个浮动环境中
  • 对于他们的标题,你应该使用\captionof{table}{...}在包中定义的captioncapt-of
  • 对于平行定位,您可以使用minipagetable如下所述

\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}

相关内容