我想水平对齐单元格内容。
\documentclass[a4paper,12pt]{article}
\usepackage{booktabs,graphicx}
\begin{document}
\centering
\begin{table}
\begin{tabular}{llll}
\toprule
Image & Name & weight & price\\
\toprule
\hspace*{-.8cm}\includegraphics[scale=0.07]{Image/dabbasPk.png} & Dabbas & 400gm & 100tk\\
\includegraphics[scale=0.15]{Image/dabbasCrownPk.jpg} & Dabbas Crown & 1kg & 270tk\\
\hspace*{-.15cm}\includegraphics[scale=0.08]{Image/neghalCrownPk.jpg} & Neghal Crown & 800gm & 220tk\\
\includegraphics[scale=0.09]{Image/zahdiPk.jpg} & Zahdi & 500gm & 90tk\\
\includegraphics[scale=0.27]{Image/zahdiCrownPk.jpeg} & Zahdi Crown & 1kg & 200tk\\
\includegraphics[scale=0.1]{Image/raisin.jpg} & Raisin(Dried grape) & 100gm & 45tk\\
\includegraphics[scale=0.2]{Image/raisinBlack.jpg} & Raizin(light Black) & 100gm & 50tk\\
\includegraphics[scale=0.3]{Image/blackSeed.jpg} & Black Seed & 100gm & 40tk\\
\includegraphics[scale=0.2]{Image/woodNut.jpg} & Woodnut & 100gm & 100tk\\
\includegraphics[scale=0.07]{Image/1.jpg} & Black Seed's Oil & 70ml & 160tk\\
\includegraphics[scale=0.07]{Image/1.jpg} & Sesame's Oil & 70ml & 100tk\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
您的意思是垂直居中图片而不是水平居中,我说得对吗?好的,这里有一个新的宏,可以完美地垂直居中图片。还请注意,您可以为所有图片设置一个通用宽度,\newcommand{\pcntr}[1]{$\vcenter{\hbox{#1}}$}
而不是手动添加。\hspace
[width=<some common value>]
\documentclass[a4paper,12pt]{article}
\usepackage{booktabs,graphicx}
\newcommand{\pcntr}[1]{$\vcenter{\hbox{#1}}$}
\begin{document}
\centering
\begin{table}
\begin{tabular}{llll}
\toprule
Image & Name & weight & price \\
\toprule
\pcntr{\includegraphics[width=2cm]{example-image}} & Dabbas & 400gm & 100tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Dabbas Crown & 1kg & 270tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Neghal Crown & 800gm & 220tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Zahdi & 500gm & 90tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Zahdi Crown & 1kg & 200tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Raisin(Dried grape) & 100gm & 45tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Raizin(light Black) & 100gm & 50tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Black Seed & 100gm & 40tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Woodnut & 100gm & 100tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Black Seed's Oil & 70ml & 160tk \\
\pcntr{\includegraphics[width=2cm]{example-image}} & Sesame's Oil & 70ml & 100tk \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
基于adjustbox
包使用的另一种解决方案:
\documentclass[a4paper,12pt]{article}
\usepackage{adjustbox} % it also load graphicx package
\usepackage{array,booktabs}
\begin{document}
\begin{table}
\centering
\adjustboxset{width=20mm,valign=c, margin=0pt 3pt 0pt 3pt}
\begin{tabular}{lllr<{\,tk}}
\toprule
Image & Name & weight & \multicolumn{1}{c}{price} \\
\midrule
\adjustimage{}{example-image-duck} & Dabbas & 400gm & 100 \\
\adjustimage{}{example-image-duck} & Dabbas Crown & 1kg & 270 \\
\adjustimage{}{example-image-duck} & Neghal Crown & 800gm & 220 \\
\adjustimage{}{example-image-duck} & Zahdi & 500gm & 90 \\
\adjustimage{}{example-image-duck} & Zahdi Crown & 1kg & 200 \\
\adjustimage{}{example-image-duck} & Raisin(Dried grape) & 100gm & 45 \\
\adjustimage{}{example-image-duck} & Raizin(light Black) & 100gm & 50 \\
\adjustimage{}{example-image-duck} & Black Seed & 100gm & 40 \\
\adjustimage{}{example-image-duck} & Woodnut & 100gm & 100 \\
\adjustimage{}{example-image-duck} & Black Seed's Oil & 70ml & 160 \\
\adjustimage{}{example-image-duck} & Sesame's Oil & 70ml & 100 \\
\bottomrule
\end{tabular}
\end{table}