50 在表格中插入【图片】以及【图文混排】如何实现垂直方向的居中对齐?

发布于 2024-09-30 14:06:20

在使用tabularray宏包实现表格内插图时,垂直方向无法完全居中。
如下面的MWE:

\documentclass{article}
\usepackage[a2paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{graphbox} % thanks to 鱼香肉丝没有鱼先生...
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
    colspec={|c|*{4}{Q[c,7cm]|}},
    rowspec={|*{4}{Q[m]|}},
}
    & short text & image without `align=m' & image with `align=m' & long text\\
    
    pure image
    & \lipsum[2] 
    & \includegraphics[width=4.8cm]{example-image} 
    & \includegraphics[align=m,width=4.8cm]{example-image}
    &\lipsum[1] \\

    image with text before
    & \lipsum[2] 
    & {some text before\\ \includegraphics[width=4.8cm]{example-image}} 
    & {some text before\\ \includegraphics[align=m,width=4.8cm]{example-image}} 
    & \lipsum[1] \\

    image with text after
    & \lipsum[2] 
    & {\includegraphics[width=4.8cm]{example-image}\\ some text after} 
    & {\includegraphics[align=m,width=4.8cm]{example-image}\\ some text after} 
    & \lipsum[1] \\
\end{tblr}
\end{document}

image.png

1处无法垂直方向居中;
2处使用graphbox提供的align=m可以实现垂直方向居中;
3/4/5/6处当出现图文混排的情况无法实现垂直方向居中;

我的问题是:对于上述情况3以及情况5中出现的情况,如何实现垂直方向的居中呢?

可参考链接:
TSE1

TSE2_对于1处偏离的solution

特别要感谢鱼香肉丝没有鱼先生@u19850 提供的graphbox解决方案

查看更多

关注者
1
被浏览
562
雾月
雾月 2024-10-01
这家伙很懒,什么也没写!

加上 varwidth 环境。

\documentclass{article}
\usepackage[a2paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{graphbox} % thanks to 鱼香肉丝没有鱼先生...
\usepackage{tabularray}
\usepackage{varwidth}

\begin{document}
\begin{tblr}{
    colspec={|c|*{4}{Q[c,m,7cm]|}},
    rowspec={|*{4}{Q|}},
}
    & short text & image without `align=m' & image with `align=m' & long text\\
    
    pure image
    & \lipsum[2] 
    & \begin{varwidth}{7cm}\includegraphics[width=4.8cm]{example-image}\end{varwidth}
    & \includegraphics[align=m,width=4.8cm]{example-image}
    &\lipsum[1] \\

    image with text before
    & \lipsum[2] 
    & {some text before\\ \includegraphics[width=4.8cm]{example-image}} 
    & {some text before\\ \includegraphics[align=b,width=4.8cm]{example-image}} 
    & \lipsum[1] \\

    image with text after
    & \lipsum[2] 
    & {\begin{varwidth}{7cm}\centering
      \includegraphics[width=4.8cm]{example-image}\\ some text after\end{varwidth}} 
    & {\includegraphics[align=t,width=4.8cm]{example-image}\\ some text after}
    & \lipsum[1] \\
\end{tblr}

\end{document}

配合 functional 库,应该可以做到检测 \includegraphics 自动加上 varwidth 环境(留作习题)。

2 个回答
烟云幻梦
烟云幻梦 2024-10-02
数学系咸鱼一枚!
\documentclass{article}
\usepackage[a2paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{graphbox} % thanks to 鱼香肉丝没有鱼先生...
\usepackage{adjustbox}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
    colspec={|c|*{4}{Q[c,7cm]|}},
    rowspec={|*{4}{Q[m]|}},
}
    & short text & image without `align=m' & image with `align=m' & long text\\
    
    pure image
    & \lipsum[2] 
    & \adjustbox{valign=m}{\includegraphics[width=4.8cm]{example-image} }
    & \adjustbox{valign=m}{\includegraphics[align=m,width=4.8cm]{example-image}}
    &\lipsum[1] \\

    image with text before
    & \lipsum[2] 
    & {some text before\\ \includegraphics[width=4.8cm]{example-image}} 
    & \adjustbox{valign=m}{
    \parbox{5cm}{\centering some text before\\ \includegraphics[align=m,width=4.8cm]{example-image}} }
    & \lipsum[1] \\

    image with text after
    & \lipsum[2] 
    & \adjustbox{valign=m}{
    \parbox{5cm}{\centering\includegraphics[width=4.8cm]{example-image}\\ some text after} }
    & \adjustbox{valign=m}{
    \parbox{5cm}{\centering\includegraphics[align=m,width=4.8cm]{example-image}\\ some text after}} 
    & \lipsum[1] \\
\end{tblr}
\end{document}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览