# Latex: Table content and border colors

0

Sometimes, it is required to have the content of a table in a different colour. If only specific elements of a table should be in different colour, \color{colour}{text} can be used easily.

	\centering
\begin{tabular}{c c c c c}
\toprule
\rowcolor{gray!30}\textcolor{blue}{T, minute} & 216 & \textcolor{red}{288} & 360 & 432\\
\midrule
\textcolor{blue}{Energy, MWh} & 468.38 & \textcolor{red}{526.03} & 573.44 & 612.33 \\
\midrule
\textcolor{blue}{Power, MW} & 2.58 & \textcolor{red}{2.63} & 2.63 & 2.58 \\
\bottomrule
\end{tabular}


If we need to change the colour of the contents to a single colour different from the main colour of the document, we change the table syntax like below:

	\centering
\begin{tabular}{>{\color{blue}}c>{\color{blue}}c>{\color{blue}}c>{\color{blue}}c>{\color{blue}}c}
\toprule
\rowcolor{gray!30} T, minute & 216 & 288 & 360 & 432\\
\midrule
Energy, MWh & 468.38 & 526.03 & 573.44 & 612.33 \\
\midrule
Power, MW & 2.58 & 2.63 & 2.63 & 2.58 \\
\bottomrule
\end{tabular}


In \begin{tabular}{}, instead of c, we have >{\color{blue}}c which identifies the colour of contents and the lines to be blue. If we wish to change the colour of the borders as well, we can use \arrayrulecolor{} as follows:

    \arrayrulecolor{red}
\centering
\begin{tabular}{>{\color{blue}}c>{\color{blue}}c>{\color{blue}}c>{\color{blue}}c>{\color{blue}}c}
\toprule
\rowcolor{gray!30} T, minute & 216 & 288 & 360 & 432\\
\midrule
Energy, MWh & 468.38 & 526.03 & 573.44 & 612.33 \\
\midrule
Power, MW & 2.58 & 2.63 & 2.63 & 2.58 \\
\bottomrule
\end{tabular}


Share if you liked:

0