![Table 中的 Tikz 图片、列的调整](https://linux22.com/image/374510/Table%20%E4%B8%AD%E7%9A%84%20Tikz%20%E5%9B%BE%E7%89%87%E3%80%81%E5%88%97%E7%9A%84%E8%B0%83%E6%95%B4.png)
我的表格中有一列是 tikzpicture,其余都是普通数据。其余列中的数据位于底部,但我希望它显示在中间。任何帮助都将不胜感激。代码如下。
\documentclass{article}
\usepackage{ booktabs }
\usepackage{tikz}
\usepackage{longtable}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC,fit}
\newcommand\addvmargin[1]{
\node[fit=(current bounding box),inner ysep=#1,inner xsep=0]{};
}
\begin{document}
\begin{longtable}{ccccc}
\label{tab!resultsraw}\\
\toprule
\multicolumn{1}{c}{ID}&\multicolumn{1}{c}{ weights Cube}&\multicolumn{1}{c}{T/J }&\multicolumn{1}{c}{data 1 }&\multicolumn{1}{c}{data 2} \\\hline
\endfirsthead
\multicolumn{4}{l}{\vspace{-0.25em}\scriptsize\emph{\tablename\ \thetable{} continued from previous page}}\\
\midrule
\endhead
\multicolumn{4}{r}{\scriptsize\emph{Continued on next page}}\\
\endfoot
\bottomrule
\endlastfoot
24097 &
$\begin{tikzpicture}[
line join=round,
y={(-0.86cm,0.36cm)},x={(.6cm,0.36cm)}, z={(0cm,.8cm)},
arr/.style={line cap=round,shorten <= 1pt}
]
\def\Side{1}
\coordinate (A1) at (0,0,0);\coordinate (A2) at (0,\Side,0);
\coordinate (A3) at (\Side,\Side,0);\coordinate (A4) at (\Side,0,0);\coordinate (B1) at (0,0,\Side);\coordinate (B2) at (0,\Side,\Side);\coordinate (B3) at (\Side,\Side,\Side);\coordinate (B4) at (\Side,0,\Side);
\draw[thin] (A2) -- (A1) -- (A4);\draw[thin] (B2) -- (B1) -- (B4) -- (B3) -- cycle;\draw[thin] (A1) -- (B1);\draw[thin] (A2) -- (B2);
\draw[thin] (A4) -- (B4);\draw[thin] (A2) -- (A3);
\draw[thin] (A3) -- (B3);\draw[thin] (A3) -- (A4);
\path[arr]
(A1) edge (A2)
(B2) edge (A2)
(B1) edge (B2)
(B1) edge (A1)
(B4) edge (A4)
(B3) edge (A3)
(B4) edge (B3)
(A4) edge (A3);
\node[below] at (A1) {$1$};
\node[below] at (A2) {$1$};
\node[below] at (A3) {$1$};
\node[below] at (A4) {$1$};
\node[above] at (B1) {$2$};
\node[above] at (B2) {$2$};
\node[above] at (B3) {$2$};
\node[above] at (B4) {$2$};
\end{tikzpicture}$ & TJJ & $1:12 $ & $[9]$ \\\hline
12960 &
$\begin{tikzpicture}[
line join=round,
y={(-0.86cm,0.36cm)},x={(.6cm,0.36cm)}, z={(0cm,.8cm)},
arr/.style={line cap=round,shorten <= 1pt}
]
\def\Side{1}
\coordinate (A1) at (0,0,0);\coordinate (A2) at (0,\Side,0);
\coordinate (A3) at (\Side,\Side,0);\coordinate (A4) at (\Side,0,0);\coordinate (B1) at (0,0,\Side);\coordinate (B2) at (0,\Side,\Side);\coordinate (B3) at (\Side,\Side,\Side);\coordinate (B4) at (\Side,0,\Side);
\draw[thin] (A2) -- (A1) -- (A4);\draw[thin] (B2) -- (B1) -- (B4) -- (B3) -- cycle;\draw[thin] (A1) -- (B1);\draw[thin] (A2) -- (B2);
\draw[thin] (A4) -- (B4);\draw[thin] (A2) -- (A3);
\draw[thin] (A3) -- (B3);\draw[thin] (A3) -- (A4);
\path[arr]
(A1) edge (A2)
(B2) edge (A2)
(B1) edge (B2)
(B1) edge (A1)
(B4) edge (A4)
(B3) edge (A3)
(B4) edge (B3)
(A4) edge (A3);
\node[below] at (A1) {$2$};
\node[below] at (A2) {$2$};
\node[below] at (A3) {$2$};
\node[below] at (A4) {$2$};
\node[above] at (B1) {$2$};
\node[above] at (B2) {$2$};
\node[above] at (B3) {$2$};
\node[above] at (B4) {$2$};
\end{tikzpicture}$ & TJ & $2:12$ &$[6]$
\end{longtable}
\end{document}
答案1
baseline={<coordinate>}
您可以使用环境选项定义基线的高度tikzpicture
。我使用当前边界框的中心使其适用于任何tikz
绘图,并将其稍微 y 方向移动以(取决于字体大小)与其他单元格垂直对齐。
\documentclass{article}
\usepackage{ booktabs }
\usepackage{tikz}
\usepackage{longtable}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC,fit}
\newcommand\addvmargin[1]{
\node[fit=(current bounding box),inner ysep=#1,inner xsep=0]{};
}
\begin{document}
\begin{longtable}{ccccc}
\label{tab!resultsraw}\\
\toprule
\multicolumn{1}{c}{ID}&\multicolumn{1}{c}{ weights Cube}&\multicolumn{1}{c}{T/J }&\multicolumn{1}{c}{data 1 }&\multicolumn{1}{c}{data 2} \\\hline
\endfirsthead
\multicolumn{4}{l}{\vspace{-0.25em}\scriptsize\emph{\tablename\ \thetable{} continued from previous page}}\\
\midrule
\endhead
\multicolumn{4}{r}{\scriptsize\emph{Continued on next page}}\\
\endfoot
\bottomrule
\endlastfoot
24097 &
$\begin{tikzpicture}[
line join=round,
y={(-0.86cm,0.36cm)},x={(.6cm,0.36cm)}, z={(0cm,.8cm)},
arr/.style={line cap=round,shorten <= 1pt},
baseline={([yshift=-.5em]current bounding box.center)},
]
\def\Side{1}
\coordinate (A1) at (0,0,0);\coordinate (A2) at (0,\Side,0);
\coordinate (A3) at (\Side,\Side,0);\coordinate (A4) at (\Side,0,0);\coordinate (B1) at (0,0,\Side);\coordinate (B2) at (0,\Side,\Side);\coordinate (B3) at (\Side,\Side,\Side);\coordinate (B4) at (\Side,0,\Side);
\draw[thin] (A2) -- (A1) -- (A4);\draw[thin] (B2) -- (B1) -- (B4) -- (B3) -- cycle;\draw[thin] (A1) -- (B1);\draw[thin] (A2) -- (B2);
\draw[thin] (A4) -- (B4);\draw[thin] (A2) -- (A3);
\draw[thin] (A3) -- (B3);\draw[thin] (A3) -- (A4);
\path[arr]
(A1) edge (A2)
(B2) edge (A2)
(B1) edge (B2)
(B1) edge (A1)
(B4) edge (A4)
(B3) edge (A3)
(B4) edge (B3)
(A4) edge (A3);
\node[below] at (A1) {$1$};
\node[below] at (A2) {$1$};
\node[below] at (A3) {$1$};
\node[below] at (A4) {$1$};
\node[above] at (B1) {$2$};
\node[above] at (B2) {$2$};
\node[above] at (B3) {$2$};
\node[above] at (B4) {$2$};
\end{tikzpicture}$ & TJJ & $1:12 $ & $[9]$ \\\hline
12960 &
$\begin{tikzpicture}[
line join=round,
y={(-0.86cm,0.36cm)},x={(.6cm,0.36cm)}, z={(0cm,.8cm)},
arr/.style={line cap=round,shorten <= 1pt},
baseline={([yshift=-.5em]current bounding box.center)},
]
\def\Side{1}
\coordinate (A1) at (0,0,0);\coordinate (A2) at (0,\Side,0);
\coordinate (A3) at (\Side,\Side,0);\coordinate (A4) at (\Side,0,0);\coordinate (B1) at (0,0,\Side);\coordinate (B2) at (0,\Side,\Side);\coordinate (B3) at (\Side,\Side,\Side);\coordinate (B4) at (\Side,0,\Side);
\draw[thin] (A2) -- (A1) -- (A4);\draw[thin] (B2) -- (B1) -- (B4) -- (B3) -- cycle;\draw[thin] (A1) -- (B1);\draw[thin] (A2) -- (B2);
\draw[thin] (A4) -- (B4);\draw[thin] (A2) -- (A3);
\draw[thin] (A3) -- (B3);\draw[thin] (A3) -- (A4);
\path[arr]
(A1) edge (A2)
(B2) edge (A2)
(B1) edge (B2)
(B1) edge (A1)
(B4) edge (A4)
(B3) edge (A3)
(B4) edge (B3)
(A4) edge (A3);
\node[below] at (A1) {$2$};
\node[below] at (A2) {$2$};
\node[below] at (A3) {$2$};
\node[below] at (A4) {$2$};
\node[above] at (B1) {$2$};
\node[above] at (B2) {$2$};
\node[above] at (B3) {$2$};
\node[above] at (B4) {$2$};
\end{tikzpicture}$ & TJ & $2:12$ &$[6]$
\end{longtable}
\end{document}
结果如下: