有人能解释一下为什么添加\adjincludegraphics{example-image-a}
会导致表格变得比文本宽度大吗?此外,我如何确保定义为的六列X[c,m]
始终具有相同的宽度,并且图像会自动重新缩放以适合各自的单元格?我想让我的表格宽度与文本宽度相同,最后六列可以灵活设置且宽度相等。我该如何实现?
(我使用 8 列是因为我需要它们用于以下行)
\documentclass{article}
\usepackage{tabularray}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\adjustboxset{width=\linewidth, valign=M}
\begin{longtblr}[
]{
colspec = { Q[c,t] Q[c] *{6}{X[c,m]} },
width = \textwidth,
hlines,
vlines,
}
NO & \SetCell[c=7]{c} Some text & & & & & & \\*
1 & \SetCell[c=7]{c} \textbf{Some text} & & & & & & \\*
& & \SetCell[c=3]{c} \begin{tblr}{colspec={Q[l]Q[c]Q[r]},rowspec={|Q[t]|Q[m]|Q[b]|}}
{Alpha \\ Alpha} & Beta & Gamma \\
Delta & Epsilon & {Zeta \\ Zeta} \\
Eta & {Theta \\ Theta} & Iota \\
\end{tblr} & & & \SetCell[c=3]{c} \begin{tblr}{colspec={Q[l]Q[c]Q[r]},rowspec={|Q[t]|Q[m]|Q[b]|}}
{Alpha \\ Alpha} & Beta & Gamma \\
Delta & Epsilon & {Zeta \\ Zeta} \\
Eta & {Theta \\ Theta} & Iota \\
\end{tblr} \\
% leave some space here
\\
& & \SetCell[c=3]{c} \begin{tblr}{
colspec={ccccc},
% vlines,
hlines,
hline{2,Z}={1pt},
hline{1}={white},
colsep=3pt,
rowsep=3pt,
row{1-Z}={font=\small},
width=\linewidth
}
\begin{tblr}{colspec={lcr},rowspec={|[2pt,green7]Q|[teal7]Q|[green7]Q|[3pt,teal7]}}
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kappa & Lambda \\
\end{tblr}
\end{tblr} & & & \SetCell[c=3]{c} \adjincludegraphics{example-image-a} \\
\end{longtblr}
\end{document}
答案1
解决您的问题的可能方法是定义图像的绝对宽度。例如宽度:
\adjustboxset{width=44mm, valign=m}
经过我们重新设计的 MWE 可以:
\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\adjustboxset{width=44mm, valign=m}
\begin{longtblr}[
caption = {Caption},
label = {tab:long+image}
]{colspec = {cQ[c,m] *{6}{X[c,m]} },
cell{1}{2} = {c=7}{},
cell{2}{2} = {c=7}{font=\bfseries},
colsep = 3pt,
hlines, vlines,
rowsep = 3pt,
rowhead = 2
}
NO & Some text
& & & & & & \\*
1 & Some text
& & & & & & \\*
& & \SetCell[c=3]{c, m}
\begin{tblr}{colsep = 3pt,
colspec = {@{} *{3}{Q[c, m]} @{}},
hline{1,Z} = {2pt, fg=teal},
hline{2-Y} = {fg=teal}
}
{Alpha\\ Alpha} & Beta & Gamma \\
Delta & Epsilon & {Zeta\\ Zeta} \\
Eta & {Theta\\ Theta} & Iota \\
\end{tblr}
& & & \SetCell[c=3]{c,m}
\begin{tblr}{colsep = 3pt,
colspec = { @{} *{3}{Q[c, m]} @{}},
hline{1,Z} = {2pt, fg=teal},
hline{2-Y} = {fg=teal}
}
{Alpha\\ Alpha} & Beta & Gamma \\
Delta & Epsilon & {Zeta\\ Zeta} \\
Eta & {Theta\\ Theta} & Iota \\
\end{tblr}
& & \\*
& & & & & & & \\*
& {Normalised\\ Coefficient}
& \SetCell[c=3]{c, m}
\begin{tblr}{colsep = 3pt,
colspec = { @{} *{3}{Q[c, m]} @{}},
hline{1,Z} = {2pt, fg=teal},
hline{2-Y} = {fg=teal}
}
{Alpha\\ Alpha} & Beta & Gamma \\
Delta & Epsilon & {Zeta\\ Zeta} \\
Eta & {Theta\\ Theta} & Iota \\
\end{tblr}
& & & \SetCell[c=3]{c}
\adjincludegraphics{example-image-a}
& & \\
\end{longtblr}
\end{document}