\rowcolor 不起作用,并且第一个单元格的文本未垂直居中

\rowcolor 不起作用,并且第一个单元格的文本未垂直居中

我遇到了困难,既试图将行颜色设置为灰色,又试图将文本(在下面的代码中称为“Txt_to_V_center”)垂直居中在图像左侧的单元格中。

我的标题如下:

\documentclass[12pt,twoside,openright]{book}
\usepackage[utf8]{inputenc}
\usepackage[francais,english]{babel}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table,xcdraw,svgnames]{xcolor}
\usepackage{mathtools,mhchem}
\usepackage{amsmath}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{float}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{subfig}
\usepackage{caption}
\usepackage[nohints]{minitoc}
\usepackage[toc,page]{appendix}
\usepackage{afterpage}
\usepackage{eso-pic}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\usepackage{lastpage}
\setlength{\parindent}{24pt}
\usepackage{esvect}
\usepackage{nicefrac}
\usepackage{listings}
\usepackage{tocloft}
\usepackage{indentfirst}
\usepackage[percent]{overpic}
\usepackage{enumitem}
\usepackage{calc}
\usepackage{marvosym}
\usepackage{multirow}
\usepackage[colorlinks,linktocpage]{hyperref}
\usepackage{gensymb}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{chemist}
\usepackage{textcomp}
\usepackage{pdfpages}
\usepackage{emptypage}
\usepackage[compact]{titlesec}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{pgfplotstable}
\usepackage{cleveref}

我的 LaTeX 代码如下:

\begin{document}      
\begin{table}[]
            \centering
            \hspace*{-2.5cm}
            \small
        \begin{tabular}{c|c|c}
        Txt_to_V_center & \includegraphics[width=.25\textwidth]{my_image.jpg} & \includegraphics[width=.25\textwidth]{my_image2.png}\\
        \rowcolor{gray!50}
        Txt1.1          & Txt1.2                                              & Txt1.3\\
        Txt2.1          & Txt2.2                                              & Txt2.3\\
        \rowcolor{gray!50}
        Txt3.1          & \begin{tabular}[c]{@{}c@{}}A\\ B \end{tabular}       & \begin{tabular}[c]{@{}c@{}}A\\ B\\ C\\ D\\ E\end{tabular}
        \end{tabular}
\end{table}
\end{document}

\rowcolors[]{1}{white}{gray!90}我也尝试过在 my\begin{table}和 my之间插入\begin{tabular},但是也没有用。

提前致谢!

答案1

  1. 使用m列:
\documentclass{article}
\usepackage[export]{adjustbox}  % for \adjincludegraphics with defined image margins 
\usepackage[table]{xcolor}

\begin{document}
        \begin{table}[htb]
    \centering
\adjustboxset{width=\linewidth,margin=0pt 3pt 0pt 3pt}
\setlength\extrarowheight{2pt}
\rowcolors{1}{white}{gray!50}
\begin{tabular}{c | >{\centering\arraybackslash}m{0.25\textwidth}|
                    >{\centering\arraybackslash}m{0.25\textwidth}  }
Txt\_to\_V\_center      & \adjincludegraphics{example-image} 
                                    & \adjincludegraphics{example-image}
                                                \\                                        
        Txt1.1          & Txt1.2    & Txt1.3    \\
        Txt2.1          & Txt2.2    & Txt2.3    \\
        Txt3.1          & A\par B   &  A\par B\par C\par D\par E
\end{tabular}
    \end{table}
\end{document}   

在此处输入图片描述

  1. 使用tabularray包和`\pgfkeys{Gin}{...}
\documentclass{article}
\usepackage[export]{adjustbox}  % for images valign  
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}
        \begin{table}[htb]
    \centering
\setkeys{Gin}{width=\linewidth}
\begin{tblr}{colspec = {c | Q[c,m, wd=0.25\textwidth]|
                           Q[c,m, wd=0.25\textwidth]},
            row{even} = {bg=gray!50}
            }
Txt\_to\_V\_center      & \includegraphics[valign=m]{example-image} 
                                    & \includegraphics[valign=m]{example-image}
                                                \\                                        
        Txt1.1          & Txt1.2    & Txt1.3    \\
        Txt2.1          & Txt2.2    & Txt2.3    \\
        Txt3.1          & A\par B   &  A\par B\par C\par D\par E
\end{tblr}
    \end{table}
\end{document}   

编译结果和以前相同。

相关内容