我正在尝试为我的页面创建一个标题,如下所示: 我用的是这个:
\documentclass[10pt,a4paper]{article}
\usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\geometry{a4paper}
\usepackage{booktabs,tabularx,multirow}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage[table]{xcolor}
\definecolor{light-gray}{gray}{0.95}
\usepackage{graphicx}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{ YYY }
\toprule
\toprule
\rowcolor{light-gray}
somthing & & something \\
\rowcolor{light-gray}
something & \includegraphics[width=0.5\linewidth]{Figures/KNTU.pdf}& something \\
\rowcolor{light-gray}
something && something \\
\bottomrule
\bottomrule
\end{tabularx}
\end{table}
\end{document}
我得到了这个:
我不明白哪里出了问题!!
答案1
这是因为\includegraphics
将图像的底部放在基线上。A\raisebox{-0.5\height}
可以解决问题。由于行有颜色,因此在顶部和底部规则之间添加垂直间距更加困难。最简单的方法是添加具有所需高度、宽度\textwidth
和与行背景相同颜色的水平规则。在下面的代码中,我在顶部规则下方和底部规则上方添加了 10pt 高的规则。
我对您的其余代码进行了一些改进:在单元格或行中使用带颜色的 booktabs 会导致单元格顶部和底部出现小白条,这是在规则周围添加垂直空间的结果\aboverulesep
。\belowrulesep
我设法弥补了这一困难。
\documentclass[10pt,a4paper]{article}
\usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\geometry{a4paper}
\usepackage{booktabs,tabularx,multirow, boldline}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage[table, svgnames]{xcolor}
\colorlet{light-gray}{Lavender!60!}
\usepackage{graphicx}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{YYY }
\toprule
\noalign{\vspace*{-1pt}}
\hlineB{2}
\noalign{\textcolor{light-gray}{\rule{\textwidth}{10pt}}}
\rowcolor{light-gray} something & & something \\
\rowcolor{light-gray}
something & \raisebox{-0.5\height}{\includegraphics[width=0.5\linewidth]{euclid}}& something \\
\rowcolor{light-gray}
something && something \\
\noalign{\textcolor{light-gray}{\rule{\textwidth}{10pt}}}
\addlinespace[-\aboverulesep]
\bottomrule
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案2
表格正好,中间的一些东西垂直对齐到底部。解决这个问题的一种方法是使用数组定义m{1.75in}
。这是我的 MWE
\documentclass[10pt,a4paper]{article}
\usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\geometry{a4paper}
\usepackage{booktabs,tabularx,multirow}
\newcolumntype{Y}{>{\centering\arraybackslash}m{1.75in}}
\usepackage[table]{xcolor}
\definecolor{light-gray}{gray}{0.95}
\usepackage{graphicx}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{ YYY }
\toprule
\toprule
\rowcolor{light-gray}
somthing & & something \\
\rowcolor{light-gray}
something & \includegraphics[width=0.5\linewidth]{example-image}& something \\
\rowcolor{light-gray}
something && something \\
\bottomrule
\bottomrule
\end{tabularx}
\end{table}
\end{document}
当然,任何其他与中心的垂直对齐都可以作为解决方案。