# [Tex/LaTex] Writing fraction in matrix

fractionsmatricesspacing

I am trying to write a fraction in a matrix. I am doing it using the following code:

$\begin{bmatrix} \frac{1}{6} & \frac{5}{6} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & \frac{1}{6} & 0 & \frac{5}{6} \\ \frac{5}{6} & 0 & 0 & \frac{1}{6} \end{bmatrix}$


What I get is as follows:

But what I am trying to achieve is:

Any help or suggestion will be appreciated.

#### Best Answer

Instead of writing \frac{a}{b}, use a/b:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$\begin{bmatrix} 1/6 & 5/6 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1/6 & 0 & 5/6 \\ 5/6 & 0 & 0 & 1/6 \end{bmatrix} \qquad \renewcommand{\frac}[2]{#1/#2} \begin{bmatrix} \frac{1}{6} & \frac{5}{6} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & \frac{1}{6} & 0 & \frac{5}{6} \\ \frac{5}{6} & 0 & 0 & \frac{1}{6} \end{bmatrix}$

\end{document}


In the second example above I've redefined the way \frac works to print it the way you want. Since the redefinition is done inside a display math group, it's normal function will be reset after \].

Of course, one could also redefine the way \frac works globally, but that would not make sense.