表格中的 Tikzpicture

表格中的 Tikzpicture

我想将 tikzpicture 置于第一列的中央。在输出中,行与行之间的图形对齐方式不同。

\documentclass[12pt]{report}
\renewcommand{\baselinestretch}{1.5}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzstyle{vertex}=[circle, draw, inner sep=0pt, minimum size=6pt]
\newcommand{\vertex}{\node[vertex]}
\newcounter{Angle}
\textwidth 5.55in
\textheight 7.35in

\begin{document}
\[\begin{array}{|b|lc|lc|lc|} 
\hline
G & \multicolumn{2}{c}{cr(G+nK_{1})} \vline & \multicolumn{2}{c|}{cr(G+P_{n})}  & \multicolumn{2}{c|} {cr(G+C_{n})}  \\ 
\hline 

%enter first row%
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
\end{tikzpicture}& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\   \hline

%%%%Entering second row%%%%
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
    \path
        (a) edge (c)
\end{tikzpicture}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\  \hline

%%%%Entering third row%%%%
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
    \path
        (a) edge (c)
        (b) edge (d)
\end{tikzpicture}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\   \hline

 \end{array}\]
\]
\begin{center}
\caption {Summary of crossing numbers for $G+nK_{1}$, $G+P_{n}$ and $G+C_{n}$.}
\end{center}

\end{document}

答案1

tikzpicture您可以在minipages中插入s

在此处输入图片描述

代码:

\documentclass[12pt]{report}
\renewcommand{\baselinestretch}{1.5}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{vertex/.style={circle, draw, inner sep=0pt, minimum size=6pt}}
%\tikzstyle{vertex}=[circle, draw, inner sep=0pt, minimum size=6pt]
\newcommand{\vertex}{\node[vertex]}
\newcounter{Angle}
\textwidth 5.55in
\textheight 7.35in

\begin{document}

\[
\begin{array}{|c|lc|lc|lc|} % a table with three centered columns separated by vertical lines
\hline
G & \multicolumn{2}{c|}{cr(G+nK_{1})} & \multicolumn{2}{c|}{cr(G+P_{n})}  & \multicolumn{2}{c|} {cr(G+C_{n})}  \\
\hline % a horizontal line to separate the headings (graphs) from the body (vertices)
%enter first row%
\begin{minipage}{0.92cm}
\vspace*{3pt}
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
\end{tikzpicture}%
\vspace*{3pt}
\end{minipage}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\   \hline
%%%%Entering second row%%%%
\begin{minipage}{0.92cm}
\vspace*{3pt}
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
    \path
        (a) edge (c);
\end{tikzpicture}%
\vspace*{3pt}
\end{minipage}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\  \hline
%%%%Entering third row%%%%
\begin{minipage}{0.92cm}
\vspace*{3pt}
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
    \path
        (a) edge (c)
        (b) edge (d);
\end{tikzpicture}%
\vspace*{3pt}
\end{minipage}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\   \hline
 \end{array}
\]

\end{document} 

附言:您的代码中有一些错误,我已经更正了......

答案2

tikzpicture您可以在嵌套的 中插入tabular,这将提供垂直对齐。必须为单元格添加更多高度,我通过本地更改 来实现\extrarowheight

\documentclass[12pt]{report}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{vertex/.style={circle, draw, inner sep=0pt, minimum size=6pt}}
\newcommand{\vertex}{\node[vertex]}

\begin{document}
\begin{table}
\centering
\setlength{\extrarowheight}{12pt}
$\begin{array}{|c|lc|lc|lc|} 
\hline
G & \multicolumn{2}{c|}{cr(G+nK_{1})} &
    \multicolumn{2}{c|}{cr(G+P_{n})}   &
    \multicolumn{2}{c|} {cr(G+C_{n})}  \\ 
\hline 

%enter first row%
\begin{tabular}{@{}c@{}}
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
\end{tikzpicture}
\end{tabular}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\   \hline
%%%%Entering second row%%%%
\begin{tabular}{@{}c@{}}
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
    \path
        (a) edge (c);
\end{tikzpicture}
\end{tabular}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\  \hline

%%%%Entering third row%%%%
\begin{tabular}{@{}c@{}}
\begin{tikzpicture}[x=0.7cm, y=0.7cm]
    \vertex (a) at (0,0) {};
    \vertex (b) at (1,0) {};
    \vertex (c) at (0,1) {};
    \vertex (d) at (1,1) {};
    \path
        (a) edge (c)
        (b) edge (d);
\end{tikzpicture}
\end{tabular}
& Z(4,n) & n\geq 1 & Z(4,n) & n\geq 1 & Z(4,n) & n\geq 3 \\   \hline

\end{array}$
\caption {Summary of crossing numbers for $G+nK_{1}$, $G+P_{n}$ and $G+C_{n}$.}
\end{table}
\end{document}

整个构造应该在一个table环境中,可能。不\[...\],在这种情况下,虽然它并没有太大的区别。我改用\centering

在此处输入图片描述

相关内容