表格对齐方式 第一行级别

表格对齐方式 第一行级别

我的第一行对齐有些问题。我希望所有行都处于同一水平。

我的代码:

\begin{table}[htb]
  \centering
  \caption{References of Questions}
  \begin{tabular}{|p{3cm}|p{20cm}|}
    \hline\rowcolor[gray]{0.8}\color{black}
    Construct         & Source of Questions \\\hline

    A & Self-developed. \\\hline
    B & Self-developed. \\\hline
    B & Self-developed. \\\hline

  \end{tabular}
  \label{tab:Definitions}
\end{table}

在此处输入图片描述

答案1

没有理由发出\color{black}。尝试将其删除,输出将如预期的那样。

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[htbp]
\centering

\caption{References of Questions}
\label{tab:Definitions}

\begin{tabular}{|p{3cm}|p{8cm}|}
\hline
\rowcolor[gray]{0.8}
Construct         & Source of Questions \\
\hline
A & Self-developed. \\
\hline
B & Self-developed. \\
\hline
B & Self-developed. \\
\hline
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

如果您确实需要更改某一p列的颜色,请在颜色命令前加上\leavevmode

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[htbp]
\centering

\caption{References of Questions}
\label{tab:Definitions}

\begin{tabular}{|p{3cm}|p{8cm}|}
\hline
\rowcolor[gray]{0.8}
\leavevmode\color{blue!70}
Construct         & Source of Questions \\
\hline
A & Self-developed. \\
\hline
B & Self-developed. \\
\hline
B & Self-developed. \\
\hline
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

笔记

  1. 永远不要忘记p选择
  2. 最好\label将 放置在 附近\caption

答案2

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\caption{References of Questions}
\label{tab:Definitions}
\begin{tblr}
{
colspec = {Q[l,m]X[l,m]},
row{1}  = {bg=gray8!60},
hlines,vlines,
}
Construct & Source of Questions \\
A         & Self-developed.     \\
B         & Self-developed.     \\
B         & Self-developed.     \\
\end{tblr}
\end{table}
\begin{table}[h]
\caption{References of Questions}
\label{tab:Definitions}
\begin{tblr}
{
colspec    = {Q[l,m]X[l,m]},
row{1}     = {bg=gray8!60},
cell{1}{1} = {fg=blue},
hlines,vlines,
}
Construct & Source of Questions \\
A         & Self-developed.     \\
B         & Self-developed.     \\
B         & Self-developed.     \\
\end{tblr}
\end{table}
\begin{table}[h]
\caption{References of Questions}
\label{tab:Definitions}
\begin{tblr}
{
colspec = {Q[l,m]X[l,m]},
row{1}  = {bg=gray8!60,fg=blue},
hlines,vlines,
}
Construct & Source of Questions \\
A         & Self-developed.     \\
B         & Self-developed.     \\
B         & Self-developed.     \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

相关内容