表格中水平线上的额外单元格/文本

表格中水平线上的额外单元格/文本

是否可以在彩色背景上或行中间的单元格中添加文本(类似于图片)?谢谢

\documentclass[11pt,a4paper]{article}
\usepackage[table]{xcolor}

\usepackage{graphicx}
\usepackage[resetfonts]{cmap}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{multicol}

\usepackage{multirow}

\textwidth 18cm
\textheight 26cm
\hoffset -1cm
\voffset -3cm
\oddsidemargin 0cm
\evensidemargin 0cm

\def\displayskip{\vskip6pt\relax}
\def\enddisplayskip{\vskip7pt\relax}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{bm}

\usepackage[flushleft]{threeparttable}

\usepackage{hhline}

\begin{document}

\begin{table}[h!]
\begingroup
\centering
\rowcolors{3}{white}{gray!20}
\def\arraystretch{1.4}
\begin{tabularx}{\textwidth}{|r|r|*{6}{>{\centering\arraybackslash}X|}l|}
\hline
          &      & \multicolumn{2}{c|}{\textbf{A}}  & \multicolumn{2}{c|}{\textbf{A}} & \multicolumn{2}{c|}{\textbf{B}}  & \\
\hhline{~~|------|~}
\multirow{-2}{*}{\textbf{A}}   & \multirow{-2}{*}{\textbf{B}}     & {\textbf{B}} & {\textbf{B}}  & \textbf{other} & \textbf{A}   & \textbf{A} & \textbf{A} & \multirow{-2}{*}{\textbf{B}} \\
\hline
     AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
     AAAAAA &   B & C  & D & E & F &  G &  -  & H \\

\hline
     AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
     AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
\hline
     AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
     AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
\hline
\end{tabularx}
\par
\endgroup
\end{table}

\end{document}

在此处输入图片描述

建议之后:

在此处输入图片描述

在此处输入图片描述

答案1

与。{NiceTabular}nicematrix

\documentclass[11pt,a4paper]{article}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage[resetfonts]{cmap}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{nicematrix,tikz}

\textwidth 18cm
\textheight 26cm
\hoffset -1cm
\voffset -3cm
\oddsidemargin 0cm
\evensidemargin 0cm
\def\displayskip{\vskip6pt\relax}
\def\enddisplayskip{\vskip7pt\relax}

\begin{document}

\begin{table}[h!]
\centering
\def\arraystretch{1.4}
\begin{NiceTabular}{rr*{6}{X[c]}l}[color-inside,vlines]
  \Hline
  \Block{2-1}{\textbf{A}} &  \Block{2-1}{\textbf{B}}    & \Block{1-2}{\textbf{A}}  && \Block{1-2}{\textbf{A}} &&
  \Block{1-2}{\textbf{B}}  && \Block{2-1}{\textbf{B}} \\
  \Hline
  &  & {\textbf{B}} & {\textbf{B}}  & \textbf{other} & \textbf{A}   & \textbf{A} & \textbf{A} & \\
  \Hline
  \rowcolors{gray!20}{}
       AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
       AAAAAA &   B & C  & D & E & F &  G &  -  & H \\

  \Hline
       AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
       AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
  \Hline
       AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
       AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
  \Hline
\CodeAfter
  \begin{tikzpicture}
  \node at (3-|1) [fill=yellow!50,right] { \small text} ; 
  \node at (5-|1) [fill=yellow!50,right] { \small text} ; 
  \node at (7-|1) [fill=yellow!50,right] { \small text} ; 
  \end{tikzpicture}
\end{NiceTabular}
\end{table}

\end{document}

您需要进行多次编译(因为nicematrix在后台使用了 PGF/TikZ 节点)。

上述代码的输出

答案2

使用旧版本的NiceMatrix

在此处输入图片描述

平均能量损失

\documentclass[11pt,a4paper]{article}
%\usepackage{xcolor, colortbl}
\usepackage{graphicx, color}
\usepackage[resetfonts]{cmap}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{nicematrix,tikz}

\textwidth 18cm
\textheight 26cm
\hoffset -1cm
\voffset -3cm
\oddsidemargin 0cm
\evensidemargin 0cm
\def\displayskip{\vskip6pt\relax}
\def\enddisplayskip{\vskip7pt\relax}

\begin{document}
    
    \begin{table}[h!]
        \centering
        \def\arraystretch{1.4}
        \begin{NiceTabular}{r*{7}{X[c]}l}
            \CodeBefore
            \rowcolors{2}{gray!15}{white!10}[respect-blocks]
            \Body
            \Hline
            \Block{2-1}{\textbf{A}} &  \Block{2-1}{\textbf{B}}    & \Block{1-2}{\textbf{A}}  && \Block{1-2}{\textbf{A}} &&
            \Block{1-2}{\textbf{B}}  && \Block{2-1}{\textbf{B}} \\
            \Hline
            &  & {\textbf{B}} & {\textbf{B}}  & \textbf{other} & \textbf{A}   & \textbf{A} & \textbf{A} & \\
            \Hline
        
            AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
            AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
            
            \Hline
            AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
            AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
            \Hline
            AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
            AAAAAA &   B & C  & D & E & F &  G &  -  & H \\
            \Hline
            \CodeAfter
            \begin{tikzpicture}
                \node at (3-|1) [fill=yellow!50,right] { \small text} ; 
                \node at (5-|1) [fill=yellow!50,right] { \small text} ; 
                \node at (7-|1) [fill=yellow!50,right] { \small text} ; 
            \end{tikzpicture}
        \end{NiceTabular}
    \end{table}
    
\end{document}

相关内容