如何修复这些错误?

如何修复这些错误?

有人能帮忙修复错误并将表格图例稍微上移吗?
你能用 TikZ 而不是 来制作表格图例吗\legend

在此处输入图片描述

在此处输入图片描述

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,shapes.geometric}
\usepackage{array}

\begin{document}

\begin{figure}[h]
\begin{tabular}{*{2}{>{\centering\arraybackslash}b{\dimexpr0.5\textwidth-2\tabcolsep\relax}}}
\legend{Weighted, complete graph $K_H$}
\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}

    &
\renewcommand{\arraystretch}{1.3}
\legend{\textbf{THIS IS TABLE LEGEND}}
\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}

\end{tabular}
\end{figure}

\end{document}

答案1

可能的解决方案:

\documentclass[varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,shapes.geometric}
\usepackage{array}

\begin{document}

\begin{figure}
\begin{tabular}{*{2}{>{\centering\arraybackslash}p{\dimexpr0.5\textwidth-2\tabcolsep\relax}}}
\textbf{Weighted, complete graph $K_H$}
    &   \textbf{THIS IS TABLE LEGEND}   \\    
\begin{tikzpicture}[baseline=(current bounding box.center),
scale=0.8,   
state/.style = {circle, draw, minimum width=5mm, inner sep=0pt}
                    ]
    \node [state] (e) at (-2, 3) [label=left:E] {};
    \node [state] (b) at ( 2, 3) [label=right:B]{};
    \node [state] (d) at (-1.25, 0.75)[label=left:D] {};
    \node [state] (c) at ( 1.25, 0.75) [label=right:C]{};
    \node [state] (a) at ( 0, 4.5) [label=above: A]{};
\draw   (a) -- (b) -- (c) -- (d) -- (e) -- (a) 
        (a) -- (c) -- (e) -- (b) -- (d) -- (a);
\end{tikzpicture}
    &   \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}
\end{tabular}
\end{figure}

\end{document}       

在此处输入图片描述

附录:

  • 如果您只需要<file name>.pfd文件,您将在主文档中使用 `\includegraphics{file.name>} 包含该文件,那么建议将上述 MWE 简化为:
% file name
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{automata}

\begin{document}

\begin{tabular}{cc}
\textbf{Weighted, complete graph $K_H$}
    &   \textbf{This is table legend}   \\
\begin{tikzpicture}[baseline=(current bounding box.center),
scale=0.8,
state/.style = {circle, draw, minimum width=5mm, inner sep=0pt}
                    ]
    \node [state] (e) at (-2, 3) [label=left:E] {};
    \node [state] (b) at ( 2, 3) [label=right:B]{};
    \node [state] (d) at (-1.25, 0.75)[label=left:D] {};
    \node [state] (c) at ( 1.25, 0.75) [label=right:C]{};
    \node [state] (a) at ( 0, 4.5) [label=above: A]{};
\draw   (a) -- (b) -- (c) -- (d) -- (e) -- (a)
        (a) -- (c) -- (e) -- (b) -- (d) -- (a);
\end{tikzpicture}
    &   \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}
\end{tabular}

\end{document}
  • 在这两种情况下您都需要注意,图像的宽度不会大于\textwidth主文档的宽度。

相关内容