在表格单元格内插入并居中数字(NiceTabular 环境、nicematrix 包)

在表格单元格内插入并居中数字(NiceTabular 环境、nicematrix 包)

我仍在学习 nicematrix 包。在这种情况下,我想在 NiceTabular 中插入图形,如果可能的话,它们具有垂直居中,并与单元格的文本处于同一水平。

我尝试使用 NiceTabular 和 pNiceArray,但没有获得理想的结果。或者我应该使用其他包?感谢您的关注!

我附上了我的代码和几张图片。

代码:

\documentclass[10pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage[svgnames,x11names]{xcolor}
\usepackage{makecell}
\usepackage{nicematrix} %Paquete bonito para tablas, matrices y arreglos
\usepackage{tikz} %Permite usar block (multicolumnas o multirenglones en este paquete)
\usepackage{booktabs} %Para utilizar comandos de tablas elegantes

\begin{table}
\centering
%\NiceMatrixOptions{cell-space-top-limit=4pt, cell-space-bottom-limit=4pt}
\begin{NiceTabular}{Wc{2cm}ll}
\toprule
\Block{2-3}{\smallskip \makecell{Área de\\Iconos} \includegraphics[scale=0.3]{barra_icn.png} } & & \\
 & &\\
\midrule
\Block{4-1}{Función} & & \\
&\includegraphics[scale=0.5]{nuevo.png}  Nuevo & \includegraphics[scale=0.5]{abrir.png} Abrir \\
&\includegraphics[scale=0.5]{guardar_como.png}  Guardar como & \includegraphics[scale=0.5]{guardar.png}  Guardar \\
& \includegraphics[scale=0.5]{borrar.png}  Borrar & \includegraphics[scale=0.5]{deshacer.png}  Deshacer/Cancelar \\
& \includegraphics[scale=0.5]{rehacer.png}  Rehacer/Revisar & \includegraphics[scale=0.5]{ajustes.png}  Ajustes \\
\bottomrule
\end{NiceTabular}
\end{table}

我得到了什么在此处输入图片描述

我希望得到什么在此处输入图片描述

答案1

  • 您有特殊使用理由吗NiceTabular
  • 在这种情况下,我看不出使用它有什么好处。
  • 使用标准表格并\adjustimage在包中定义adjustbox您可以获得下表:

在此处输入图片描述

  • 上述结果足以仅编译以下 MWE 一次:
\documentclass[a4paper]{report}
\usepackage[spanish]{babel}
\usepackage{amsmath, amssymb}
\usepackage[margin=2cm]{geometry}

\usepackage[demo, % in real document remove "demo" option
            export]{adjustbox} % for vertical centering ofimages
\usepackage[svgnames,x11names]{xcolor}
\usepackage{booktabs, makecell, multirow}
\usepackage{nicematrix} %Paquete bonito para tablas, matrices y arreglos
\usepackage{tikz} %Permite usar block (multicolumnas o multirenglones en este paquete)
            
\begin{document}
    \begin{table}
    \centering
    \adjustboxset{height=2cm, width=2cm, % adjust images size according to your needs
                  valign=c, margin=3pt}  
\begin{tabular}{>{\bfseries}Wc{2cm} l l }
    \toprule
\makecell{Área de\\Iconos} & \multicolumn{2}{c}{\adjustimage{width=8cm, height=1cm}{barra_icn}}\\
    \midrule
\multirow{17}{*}{Función}   
    & \adjustimage{}{nuevo}  Nuevo 
        & \adjustimage{}{abrir} Abrir \\
    %\addlinespace
    & \adjustimage{}{guardar_como}  Guardar como 
        & \adjustimage{}{guardar}  Guardar \\
    %\addlinespace
    & \adjustimage{}{borrar}  Borrar 
        & \adjustimage{}{deshacer}  Deshacer/Cancelar \\
    %\addlinespace
    & \adjustimage{}{rehacer}  Rehacer/Revisar 
        & \adjustimage{}{ajustes}  Ajustes \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

附录 您可以使用最新版本的nicematrix软件包获得类似的结果,但是您需要编译 MWE 两次:

\documentclass[a4paper]{report}
\usepackage[spanish]{babel}
\usepackage{amsmath, amssymb}
\usepackage[margin=2cm]{geometry}

\usepackage[demo,
            export]{adjustbox}
\usepackage[svgnames,x11names]{xcolor}
\usepackage{booktabs, makecell}
\usepackage{nicematrix} %Paquete bonito para tablas, matrices y arreglos
%\usepackage{tikz} %Permite usar block (multicolumnas o multirenglones en este paquete)
            
\begin{document}
    \begin{table}
    \centering
    \setkeys{Gin}{height=2cm, width=2cm}
\NiceMatrixOptions{cell-space-top-limit=3pt, cell-space-bottom-limit=3pt}
  
\begin{NiceTabular}{>{\bfseries}Wc{2cm} l l }
    \toprule
\makecell{Área de\\Iconos} & \multicolumn{2}{c}{\includegraphics[width=8cm, height=1cm,
                                                                 valign=c]{barra_icn}}\\
    \midrule
\Block{4-1}{\textbf{Función}}   
    & \includegraphics[valign=c]{nuevo}  Nuevo
        & \includegraphics[valign=c]{abrir} Abrir \\
    %\addlinespace
    & \includegraphics[valign=c]{guardar_como}  Guardar como
        & \includegraphics[valign=c]{guardar}  Guardar \\
    %\addlinespace
    & \includegraphics[valign=c]{borrar}  Borrar
        & \includegraphics[valign=c]{deshacer}  Deshacer/Cancelar \\
    %\addlinespace
    & \includegraphics[valign=c]{rehacer}  Rehacer/Revisar
        & \includegraphics[valign=c]{ajustes}  Ajustes \\
    \bottomrule
\end{NiceTabular}
    \end{table}
\end{document}

相关内容