# Writing fraction in matrix

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.

• instead of \frac{a}{b}, you should just write a/b. It's that straight-forward.
– Werner
Commented Jan 12, 2016 at 20:34
• Yes!! It works. I thought complex. Commented Jan 12, 2016 at 20:36

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.

You can use the nicefrac package:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{mathtools}
\usepackage{nicefrac}

\begin{document}

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

\end{document}