4

How to adjust the width and the color of the line in between numerator and denominator in a mathematical fraction? I have seen this question but it does not help.

MWE:

\documentclass{article}
\usepackage{xcolor}

\begin{document}

\begin{equation}
\color{red} y = \frac{x}{z}
\end{equation}  

\end{document}

enter image description here

luchonacho
  • 4,161

2 Answers2

3

This may be an awkward way to do it but you can color the fraction and then return the numerator and denominator to black:

$ y = \color{red} \frac{\color{black} x}{\color{black} z}$

In general you would need some foolproof way to ensure that the red color doesn't leak out elsewhere. This might (or might not) do it:

\def\redfrac#1#2{\begingroup \color{red}
  \frac{\color{black}#1}{\color{black}#2}\endgroup}

Of course, a proper definition would use whatever color is current rather than force black. However, that exceeds my understanding of the internals of the color or xcolor package.

Dan
  • 6,899
3

You have to typeset the fraction with the selected color and go back to the previous color for the numerator and denominator.

With \genfrac you can set the thickness of the fraction bar.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\newcommand{\colorfrac}[4][]{%
  \begingroup
  \colorlet{currentcolor}{.}%
  \textcolor{#2}{%
    \genfrac{}{}{#1}{}{\textcolor{currentcolor}{#3}}{\textcolor{currentcolor}{#4}}%
  }%
  \endgroup
}

\begin{document}

\[
y=\colorfrac[1pt]{red}{x}{z}
\]

\leavevmode\color{blue}Some blue text
\[
y=\colorfrac[2pt]{red}{x}{z}
\]

\end{document}

enter image description here

egreg
  • 1,121,712