84

How can I change the color of the lines (the frame) in a tabular environment? In the following MWE:

\begin{tabular}{c|c|c}
a&b&c \\ \hline
d&e&f \\ \hline
g&h&i
\end{tabular}

I would like the horizontal and vertical lines of the table to have, say a blue color.

2

3 Answers 3

108

You can use the colortbl package for this. It works as follows:

\documentclass{article}
\usepackage{colortbl}
\begin{document}
  \begin{tabular}{l!{\color{green}\vrule}l}
    \arrayrulecolor{red}\hline
    test & test\\\arrayrulecolor{blue}\hline
  \end{tabular}
\end{document}

Looks like this:

Array with coloured rules

6
  • 21
    Or the xcolor package with the table option (internally loading colortbl and giving access to the full xcolor capacity). Jan 10, 2012 at 16:08
  • 2
    the command \arrayrulecolor{red} is exactly what i need. Jan 10, 2012 at 19:09
  • 1
    Note that the arrayrulecolor command also applies to the \toprule, \midrule and \bottomrule commands defined in the booktabs package.
    – ph0t0nix
    May 18, 2016 at 9:03
  • 1
    How do you reset this to the default color afterward? I am guessing that the default is usually black, but I am not sure. Jul 21, 2019 at 20:52
  • 1
    Yes. An answer here suggests that the current color is defined as .. Thus, . is the default color at the beginning of the document. That means that you can define a new color to match . at the beginning of the document and then use that color to reset to the default. In the preamble: \AtBeginDocument{\colorlet{defaultcolor}{.}}. Where you want to reset the rule color: \arrayrulecolor{defaultcolor}. Oct 19, 2019 at 18:45
27

The tabu package could also be helpful here.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{tabu}

\begin{document}
  \taburulecolor{blue}
  \begin{tabu}{c|c|c}
    a & b & c \\ \hline
    d & e & f \\ \hline
    g & h & i
  \end{tabu}
\end{document}
3
  • i voted for wh1t3's solution, because, i need this in a very long document, with many tabular that are already written, and i don't want to change the environment. But the package tabu seems looks very interesting. Thank you Jan 10, 2012 at 19:11
  • 2
    @nicolasroy: You can still upvote Thorsten's answer as well of course. Jan 10, 2012 at 19:36
  • i've have been fighting in understanding how ot officially registerd in this forum... precisely with this purpose :) Jan 10, 2012 at 20:01
1

An alternative solution with tblr environment of tabularray package:

\documentclass{article}

\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{
  cells = {c},
  hlines = {red3},
  vlines = {blue3},
}
  a & b & c \\
  d & e & f \\
  g & h & i \\
\end{tblr}

\end{document}

enter image description here

You must log in to answer this question.

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