2

I have some issues with the alignment of my first row. I want it all to be at the same level.

My code:

\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}

enter image description here

0

2 Answers 2

3

There's no reason to issue \color{black}. Try removing it and the output will be as expected.

\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}

enter image description here

If you really need to change color in a p column, precede the color command with \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}

enter image description here

Notes

  1. Never forget the p option
  2. The \label is better placed near the \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}

enter image description here

2
  • +1, but you may show that coloring text is simpler and doesn't make any problems (for example: fg=blue as shown in egreg answer).
    – Zarko
    Commented Mar 27, 2023 at 1:38
  • @Zarko Thanks. I have updated.
    – Clara
    Commented Mar 27, 2023 at 2:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .