3

How can I change the color of bracket in following matrix.

\begin{bmatrix} 1 & 0.5 \end{bmatrix}

I want entries in black while [ ] in red. Is it possible to do it using bmatrix

6

Here I provide bmatrixcolor with an optional argument for the color. EDITED to save the pre-existing color, rather than returning to black, using the xcolor feature . to refer to the current color. In this way, the matrix data will be set in the prevailing color.

\documentclass{article}

\usepackage{amsmath,xcolor}
\newenvironment{bmatrixcolor}[1][red]
  {\colorlet{savethecolor}{.}\colorlet{bracecolor}{#1}%
    \color{bracecolor}\left[\color{savethecolor}\begin{matrix}}
  {\end{matrix}\color{bracecolor}\right]}

\begin{document}
\[
\begin{bmatrix} 1 & 0.5 \end{bmatrix}
\]
\[
\begin{bmatrixcolor} 1 & 0.5 \end{bmatrixcolor}
\]
\[
\begin{bmatrixcolor}[blue] 1 & 0.5 \end{bmatrixcolor}
\]
\color{red}
\[
x =\begin{bmatrixcolor}[blue] 1 & 0.5 \end{bmatrixcolor}\!^T
\]
\end{document}

enter image description here

  • 1
    You saved me an answer. The last color setting is not necessary, though. – egreg Sep 14 '16 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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