4

I want to be able to change the color of a matrix brackets. I have found this answer but it is not exactly what I am looking for, since with this answer the subindex just right outside the matrix is not at the desired height. I would like to be able to write something similar to

\begin{equation*}
   \begin{pmatrix}
        1 \\
        2 \\
        -1
   \end{pmatrix}_{\!\!e}
\end{equation*}

and obtain

enter image description here

but with a different color for the brackets (and maybe also a different color for the subindex).

4
  • 6
    Does this answer your question? how to change color of matrix bracket Oct 26, 2020 at 8:58
  • 1
    @SachchidanandPrasad -- The OP mentioned, that that answer messes with the positioning of the subscript
    – DG'
    Oct 26, 2020 at 11:47
  • 1
    @SachchidanandPrasad It does not. As I mention in the post, I had already seen this answer, but it messes with the positioning of the subscript, as #DG' says. Oct 26, 2020 at 12:06
  • 1
    @Just_a_newbie Yeah just saw that, sorry for this. Oct 26, 2020 at 14:32

2 Answers 2

3
\documentclass{article}
\usepackage{amsmath,xcolor,environ}

\NewEnviron{pmatrixcolor}[1][red]{%
  \colorlet{currentcolor}{.}%
  \mathinner{\begingroup\color{#1}\left(\color{currentcolor}%
    \begin{matrix}
      \BODY
    \end{matrix} \color{#1}\right)\endgroup}}

\begin{document}
\[
    \begin{pmatrix}
        1 \\
        2 \\
        -1
    \end{pmatrix}
    _e
\]

\[
    \begin{pmatrixcolor}
        1 \\
        2 \\
        -1
    \end{pmatrixcolor}
    _e
\]
\end{document}

enter image description here

1
  • 1
    Thank you, this is exactly what I was looking for! Oct 27, 2020 at 10:40
2

The environment {pNiceMatrix} of nicematrix has a key delimiters/color for the color of the delimiters.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\[
    \begin{pmatrix}
        1 \\
        2 \\
        -1
    \end{pmatrix}
    _e
\]

\[
    \begin{pNiceMatrix}[delimiters/color=red]
        1 \\
        2 \\
        -1
    \end{pNiceMatrix}
    _e
\]
\end{document}

Ouput of the above code

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.