How to change the rules (line) color of a table in LaTeX?
In this tutorial, you will learn how to change the color of lines or rules of a table in LaTeX.
To set the line color of a table in LaTeX, you can use the xcolor
package with the [table]
option. Like \usepackage[table]{xcolor}
, then you can use the \arrayrulecolor{<color>}
command before tabular
.
Also, you can do a similar thing with the colortbl
package.
\documentclass{article} \usepackage[table]{xcolor} % \usepackage{colortbl} % Or use this package \begin{document} \begin{table}[h] \centering \arrayrulecolor{red} % Change color of table lines (rules) \begin{tabular}{|c|c|c|} \hline Column 1 & Column 2 & Column 3 \\ \hline Text & Text & Text \\ \hline Text & Text & Text \\ \hline Text & Text & Text \\ \hline \end{tabular} \caption{Colored lines of a Table} \end{table} \begin{table}[h] \centering \arrayrulecolor{blue} % Change color of table lines (rules) \begin{tabular}{|c|c|c|} \hline Column 1 & Column 2 & Column 3 \\ \hline Text & Text & Text \\ \hline Text & Text & Text \\ \hline Text & Text & Text \\ \hline \end{tabular} \caption{Colored lines of a Table} \end{table} \end{document}
Output:
Specific color for specific line in the table
If you want to add a specific color for a specific line then you can use the \arrayrulecolor{<color>}
command with the specific \hline
. And for vertical lines, you have to use !{\color{<color-name>}\vrule}
, when we set the column alignment of the table.
\documentclass{article} \usepackage[table]{xcolor} % \usepackage{colortbl} % Or use this package \begin{document} \begin{table}[h] \centering \begin{tabular}{!{\color{blue}\vrule}c!{\color{green}\vrule}c!{\color{lime}\vrule}} \hline Column 1 & Column 2 \\ \arrayrulecolor{yellow}\hline Text & Text \\ \arrayrulecolor{red}\hline Text & Text \\ \arrayrulecolor{brown}\hline Text & Text \\ \hline \end{tabular} \caption{Colored lines of a Table} \end{table} \end{document}
Output:
Change line color with tabu package
You can also use the tabu
package to set color of the lines of a table. This package provides a tabu
environment to make tables and \taburulecolor{<color>}
command to set color of lines.
\documentclass{article} \usepackage{xcolor} \usepackage{tabu} \begin{document} \taburulecolor{green!30!black} \begin{tabu}{|c|c|c|} \hline Column 1 & Column 2 & Column 3 \\ \hline Text & Text & Text \\ \hline Text & Text & Text \\ \hline Text & Text & Text \\ \hline \end{tabu} \end{document}
Output:
Leave a Reply