2

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:

enter image description here

But what I am trying to achieve is:

enter image description here

Any help or suggestion will be appreciated.

2
  • 2
    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

2 Answers 2

6

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

enter image description here

\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.

6

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} 

enter image description here

You must log in to answer this question.

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