如何在表格中绘制多个 tikz 图形?

如何在表格中绘制多个 tikz 图形?

我想创建一个包含许多 tikz 图形的表。

这是最小的工作示例。

编辑:我设法画了出来。但看起来不太好。我还需要每个图的标题。

\documentclass[11pt]{article}
\usepackage{graphicx,amsthm,amsmath,amsfonts,amssymb,latexsym,amscd,mathrsfs,textcomp,booktabs,float,geometry, hyperref}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes,calc,positioning}
\begin{document}
\begin{table}[H]
\centering
\begin{minipage}{\linewidth}
\resizebox{0.93\linewidth}{!}{
\begin{tabular}{|cc|}
\hline
\tdplotsetmaincoords{0}{0}
\begin{tikzpicture}[tdplot_main_coords, thick]
 \foreach \x in {1,...,5}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (d\x) at ({4*cos((\x-1)*72)},{4*sin((\x-1)*72)},0) {};}
\foreach \x in {1,2}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (t\x) at (-7,{3*cos((\x-1)*180)},0) {};}
\foreach \x in {1,...,5}{
\foreach \y in {\x,...,5}{
\draw[color=red] (d\x)--(d\y);}}
\draw[color=blue] (t1)--(t2);
\end{tikzpicture}
\end{figure}&\begin{figure}[H]
\centering
\tdplotsetmaincoords{50}{-18}
\begin{tikzpicture}[tdplot_main_coords, thick]
\foreach \x in {1,...,8}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (d\x) at (0,{4*cos((\x-1)*45)},{4*sin((\x-1)*45)}) {};}
\node[shape=circle,draw,fill=black,inner sep=1pt] (O) at (-5,0,0){};
\foreach \x in {1,2}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (t\x) at (5,{4*cos((\x-1)*180)},{4*sin((\x-1)*180)}) {};}
\foreach \d in {1,...,8}{
\draw[color=blue] (O)--(d\d);}
\foreach \x in {1,...,8}{
\foreach \y in {\x,...,8}{
\draw[color=red] (d\x)--(d\y);}}
\foreach \x in {1,...,8}{
\foreach \y in {1,2}{
\draw[color=green] (d\x)--(t\y);}}
\foreach \x in {1,2}{
\foreach \y in {\x,...,2}{
\draw[color=black] (t\x)--(t\y);}}
\end{tikzpicture}
\\
\tdplotsetmaincoords{0}{0}
\begin{tikzpicture}[tdplot_main_coords, thick]
  \foreach \x in {1,...,5}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (d\x) at ({4*cos((\x-1)*72)},{4*sin((\x-1)*72)},0) {};}
\foreach \x in {1,2}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (t\x) at (-7,{3*cos((\x-1)*180)},0) {};}
\foreach \x in {1,...,5}{
\foreach \y in {\x,...,5}{
\draw[color=red] (d\x)--(d\y);}}
\draw[color=blue] (t1)--(t2);
\end{tikzpicture}
&
\tdplotsetmaincoords{50}{-18}
\begin{tikzpicture}[tdplot_main_coords, thick]
  \foreach \x in {1,...,8}{%
    \node[shape=circle,draw,fill=black,inner sep=1pt] (d\x) at (0,{4*cos((\x-1)*45)},{4*sin((\x-1)*45)}) {};}
\node[shape=circle,draw,fill=black,inner sep=1pt] (O) at (-5,0,0){};
\foreach \x in {1,2}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (t\x) at (5,{4*cos((\x-1)*180)},{4*sin((\x-1)*180)}) {};}
\foreach \d in {1,...,8}{
\draw[color=blue] (O)--(d\d);}
\foreach \x in {1,...,8}{
\foreach \y in {\x,...,8}{
\draw[color=red] (d\x)--(d\y);}}
\foreach \x in {1,...,8}{
\foreach \y in {1,2}{
\draw[color=green] (d\x)--(t\y);}}
\foreach \x in {1,2}{
\foreach \y in {\x,...,2}{
\draw[color=black] (t\x)--(t\y);}}
\end{tikzpicture}
\end{figure}\\
\hline
\end{tabular}
\end{table} 
}
\end{minipage}
\end{document}

在此处输入图片描述

谢谢。

答案1

从您的 MWE 我成功生成了下图:

在此处输入图片描述

我对您原来的 MWE 做了以下更改:

  • 删除所有figure浮动
  • 对于表格中的标题,我添加了包caption;它可以使用captionof,可以在浮点数之外使用
  • 对于列类型我添加了array可以定义的包>{\centering\arraybackslash}p{0.5\textwidth},因此表格宽度数字占据整个文本宽度
  • 我还清理了代码中所有不太必要的花括号,并在编辑器中重新格式化它的外观(根据我的喜好)
  • 我留下了表格规则,仅供参考。在最终版本中,这些规则可以省略。

整个 MWE 是:

\documentclass[11pt]{article}
    \usepackage{graphicx}
    \usepackage{caption}% <--- added    
    \usepackage{array,booktabs}% <--- added array     \usepackage{amsthm,amsmath,amsfonts,amssymb,latexsym,amscd,mathrsfs}
    \usepackage{textcomp,float}
    \usepackage[margin=25mm]{geometry}

    \usepackage{tikz}
    \usepackage{tikz-3dplot}
    \usetikzlibrary{shapes,calc,positioning}

    \usepackage{hyperref}

\begin{document}
    \begin{table}[htb]
\begin{tabular}{|*{2}{>{\centering\arraybackslash}p{0.5\textwidth}|}}
    \hline
    \tdplotsetmaincoords{0}{0}
    \begin{tikzpicture}[tdplot_main_coords, thick,scale=0.5]
\foreach \x in {1,...,5}
    \node[shape=circle,draw,fill=black,inner sep=1pt]
        (d\x) at ({4*cos((\x-1)*72)},{4*sin((\x-1)*72)},0) {};
\foreach \x in {1,2}
\node[shape=circle,draw,fill=black,inner sep=1pt] 
    (t\x) at (-7,{3*cos((\x-1)*180)},0) {};
\foreach \x in {1,...,5}
{
    \foreach \y in {\x,...,5}\draw[color=red] (d\x)--(d\y);
}
\draw[color=blue] (t1)--(t2);
    \end{tikzpicture}
\captionof{figure}{graph 0}  \label{g0}
    &
    \tdplotsetmaincoords{50}{-18}
    \begin{tikzpicture}[tdplot_main_coords, thick,scale=0.5]
\foreach \x in {1,...,8}%
    \node[shape=circle,draw,fill=black,inner sep=1pt] 
        (d\x) at (0,{4*cos((\x-1)*45)},{4*sin((\x-1)*45)}) {};
\node[shape=circle,draw,fill=black,inner sep=1pt] (O) at (-5,0,0){};
\foreach \x in {1,2}
\node[shape=circle,draw,fill=black,inner sep=1pt] 
    (t\x) at (5,{4*cos((\x-1)*180)},{4*sin((\x-1)*180)}) {};
\foreach \d in {1,...,8} 
    \draw[color=blue] (O)--(d\d);
\foreach \x in {1,...,8}
{
\foreach \y in {\x,...,8}
\draw[color=red] (d\x)--(d\y);
}
\foreach \x in {1,...,8}
{
\foreach \y in {1,2}
    \draw[color=green] (d\x)--(t\y);
}
\foreach \x in {1,2}
{
\foreach \y in {\x,...,2}
\draw[color=black] (t\x)--(t\y);
}
    \end{tikzpicture}
\captionof{figure}{graph 1} \label{g1}
                    \\  \hline
\tdplotsetmaincoords{0}{0}
\begin{tikzpicture}[tdplot_main_coords, thick,scale=0.5]
\foreach \x in {1,...,5}
    \node[shape=circle,draw,fill=black,inner sep=1pt] 
        (d\x) at ({4*cos((\x-1)*72)},{4*sin((\x-1)*72)},0) {};
\foreach \x in {1,2}{%
\node[shape=circle,draw,fill=black,inner sep=1pt] (t\x) at (-7,{3*cos((\x-1)*180)},0) {};}
\foreach \x in {1,...,5}{
\foreach \y in {\x,...,5}{
\draw[color=red] (d\x)--(d\y);}}
\draw[color=blue] (t1)--(t2);
\end{tikzpicture}
\captionof{figure}{graph 2} \label{g2}
    &
\tdplotsetmaincoords{50}{-18}
\begin{tikzpicture}[tdplot_main_coords, thick,scale=0.5]
  \foreach \x in {1,...,8}{%
    \node[shape=circle,draw,fill=black,inner sep=1pt] (d\x) at (0,{4*cos((\x-1)*45)},{4*sin((\x-1)*45)}) {};}
\node[shape=circle,draw,fill=black,inner sep=1pt] (O) at (-5,0,0){};
\foreach \x in {1,2}
    \node[shape=circle,draw,fill=black,inner sep=1pt] 
        (t\x) at (5,{4*cos((\x-1)*180)},{4*sin((\x-1)*180)}) {};
\foreach \d in {1,...,8}
    \draw[color=blue] (O)--(d\d);
\foreach \x in {1,...,8}
{
\foreach \y in {\x,...,8}
    \draw[color=red] (d\x)--(d\y);
}
\foreach \x in {1,...,8}
{
\foreach \y in {1,2}
    \draw[color=green] (d\x)--(t\y);
}
\foreach \x in {1,2}
{
\foreach \y in {\x,...,2}
    \draw[color=black] (t\x)--(t\y);
}
\end{tikzpicture}
\captionof{figure}{graph 3} \label{g3}
    \\
    \hline
\end{tabular}
\end{table}

\end{document}

相关内容