TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
2  
instead of \frac{a}{b}, you should just write a/b. It's that straight-forward. – Werner Jan 12 at 20:34
    
Yes!! It works. I thought complex. – Mohammad Saifullah Jan 12 at 20:36
up vote 4 down vote accepted

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.