我想在表格中包含预览并强制文本居中或顶部对齐。如何在不重新定义整个文档的 X 列的情况下实现此目的?
这是我的 MRE:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{hyperref}
\IfFileExists{4D5GD.png}{}{\write18{wget https://i.stack.imgur.com/4D5GD.png}}
\begin{document}
\begin{table}
\caption{A table}
\begin{tabularx}{\linewidth}{lXr}
\toprule
\textbf{Overview} & \textbf{Description} & \textbf{Hyperlink} \\
\midrule
\includegraphics[height=2cm]{4D5GD.png} & Lorem Ipsum &
\href{ttps://i.stack.imgur.com/4D5GD.png}{Link} \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案1
利用adjustbox
包的帮助将图像基线移动到图像顶部:
\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{hyperref}
\IfFileExists{4D5GD.png}{}{\write18{wget https://i.stack.imgur.com/4D5GD.png}}
\begin{document}
\begin{table}
\caption{A table}
\begin{tabularx}{\linewidth}{lXr}
\toprule
\textbf{Overview} & \textbf{Description} & \textbf{Hyperlink} \\
\midrule
\includegraphics[height=2cm, valign=t]{example-image-duck}%{4D5GD.png}
& Lorem Ipsum & \href{ttps://i.stack.imgur.com/4D5GD.png}{Link} \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
但是使用包tblr
中定义的表,tabularray
移动图像基线不再需要,因此您可以使用graphicx
包代替`adjustbox。除此之外,编译结果比以前更好:
\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{hyperref}
\IfFileExists{4D5GD.png}{}{\write18{wget https://i.stack.imgur.com/4D5GD.png}}
\begin{document}
\begin{table}
\caption{A table}
\begin{tblr}{colspec = {Q[c,h] X[h] Q[r,h]}}
\toprule
\textbf{Overview} & \textbf{Description} & \textbf{Hyperlink} \\
\midrule
\includegraphics[height=2cm, valign=t]{example-image-duck}%{4D5GD.png}
& Lorem Ipsum & \href{ttps://i.stack.imgur.com/4D5GD.png}{Link} \\
\bottomrule
\end{tblr}
\end{table}
\end{document}