Math & ScienceGray Rules in a Matrix

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Gray Rules in a Matrix

Post by Cham »

I would like to add some gray lines inside a matrix, like this simple example :

Code: Select all

\begin{equation}
	M = \left[ \begin{array}{c|ccc}
		A & 0 & 0 & 0 \\
		\hline 0 & B & 0 & 0 \\
		0 & 0 & C & 0 \\
		0 & 0 & 0 & D \\
		\end{array} \right]
\end{equation}
Currently, the two lines in this matrix (a vertical line and an horizontal line) are plain black. Is it possible to turn both of them medium gray ?
Last edited by Cham on Fri Jan 13, 2012 8:53 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Gray Rules in a Matrix

Post by localghost »

The colortbl package is your friend (here loaded by the »table« option for the xcolor package).

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table]{xcolor}

\begin{document}
  \begin{equation}
    \arrayrulecolor{gray!50}
    M = \left[
    \begin{array}{c|ccc}
      A & 0 & 0 & 0 \\
      \hline 0 & B & 0 & 0 \\
      0 & 0 & C & 0 \\
      0 & 0 & 0 & D \\
    \end{array}
    \right]
  \end{equation}
\end{document}

Thorsten
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Gray Rules in a Matrix

Post by Cham »

It works ! Thanks a lot for the tip !

But why the option "dvipsnames" ?

And what is the range of the gray color parameter ? I thought that it was from 0 to 255, but it gives an error if above 200.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Gray Rules in a Matrix

Post by localghost »

Cham wrote:[…] But why the option "dvipsnames"? […]
Just habit. Drop it if you want. For details about this option see the xcolor manual.
Cham wrote:[…] And what is the range of the gray color parameter ? I thought that it was from 0 to 255, but it gives an error if above 200.
It's a percentage value. For details about color specification see the xcolor manual.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Gray Rules in a Matrix

Post by Cham »

localghost wrote: It's a percentage value.
A percentage ? It should then give an error if the value is higher than 100%. I don't get any error until 201.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Gray Rules in a Matrix

Post by localghost »

According to Section 1.1 of the package manual it is a percentage value. Can't tell you more.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Gray Rules in a Matrix

Post by Cham »

Ok. Anyway, I defined my own color in the preambule, and my initial query is solved.

Thanks a lot again. 8-)
Post Reply