![如何将图像放在表格的多个列上?](https://linux22.com/image/383950/%E5%A6%82%E4%BD%95%E5%B0%86%E5%9B%BE%E5%83%8F%E6%94%BE%E5%9C%A8%E8%A1%A8%E6%A0%BC%E7%9A%84%E5%A4%9A%E4%B8%AA%E5%88%97%E4%B8%8A%EF%BC%9F.png)
答案1
这有一些可能性。
\documentclass{article}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usepackage{array}
% table partly adpated from https://tex.stackexchange.com/a/168257/121799
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{center}
\begin{table}[!htbp]
\noindent
\begin{tabular}{|p{3cm}|C{2cm}
|C{2.2cm}
|C{2cm}|}
\hline
\rowcolor{gray!50}
sth & sth & sth & sth \\
\hline
\rowcolor{gray!50}
& \multicolumn{3}{c|}{
\tikz{\draw[fill=blue] (0,0.1) -- (4,0) -- (4,0.3) -- (0,0.2);}}\\
\hline
\rowcolor{gray!50}
& \multicolumn{3}{c|}{
\tikz{\fill[blue] (0,0) -- (4,0.1) -- (4,0.3) -- (0,0.4);}}\\
\hline
& \multicolumn{3}{c|}{\tikz{\path (2,0.3);
\draw[very thick,-latex] (0,0) -- (4,0)
node[midway,below,font=\sffamily\small]{blah blah blah};
\draw[very thick,-latex] (4,-1) -- (0,-1)
node[midway,below,font=\sffamily\small]{blah blah blah};
}} \\
\hline
\end{tabular}
\label{tab:xyz}
\end{table}
\end{center}
\end{document}
答案2
- 另一种可能性是:
- 为图像定义基线,以便在多列单元格中更好地定位图像
- 使用包后,
cellspace
图像周围的垂直空间增加了
由于您没有提供 mwe,因此在表格中使用虚拟文本并设置所有列的相同宽度。
\documentclass{article} \usepackage[table]{xcolor} \usepackage{tikz} \usetikzlibrary{arrows.meta, quotes} \usepackage{cellspace} \setlength\cellspacetoplimit{4pt} \setlength\cellspacebottomlimit{4pt} \begin{document} \begin{table}[!htbp] \centering \begin{tabular}{|*{4}{p{3cm}|}} \hline \rowcolor{gray!50} text & text & text & text \\ \hline \rowcolor{gray!50} text & \multicolumn{3}{Sc|}{ \tikz[baseline=(current bounding box.base)]{ \path[draw=blue,fill=blue!30,thick] (0,0.1) -- (6,0.3) -- (6,-0.3) -- (0,-0.1) -- cycle;} } \\ \hline \rowcolor{gray!50} text & \multicolumn{3}{Sc|}{ \tikz[baseline=(current bounding box.base)]{ \path[draw=blue,fill=blue!30,thick] (0,0.3) -- (6,0.1) -- (6,-0.1) -- (0,-0.3) -- cycle;} } \\ \hline some longer text in two lines & \multicolumn{3}{Sc|}{ \tikz[font=\sffamily\small, ultra thick, >=Straight Barb, auto=right, baseline=(current bounding box.base)]{ \draw[->] (0, 0.0) to ["some longer one line quotes"] +(6,0); \draw[<-] (0,-0.8) to ["some longer one line quotes"] +(6,0);} } \\ \hline \end{tabular} \end{table} \end{document}
这使: