TransWikia.com

how to change color of matrix bracket

TeX - LaTeX Asked by NAASI on December 26, 2020

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

2 Answers

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

Correct answer by Steven B. Segletes on December 26, 2020

The package nicematrix provides in the version 5.7 (2020-11-23) a key delimiters-color for the color of the delimiters in its environments (similar to the environments of amsmath).

documentclass{article}

usepackage{nicematrix}

begin{document}


$begin{bmatrix}
1 & 2 
3 & 4
end{bmatrix}$qquad
$begin{bNiceMatrix}[delimiters-color=red] 
1 & 2 
3 & 4
end{bNiceMatrix}$

end{document}

Output of the above code

Answered by F. Pantigny on December 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP