TeX - LaTeX Asked by ArtWooD on June 13, 2021
I’ve made a bordermatrix with brackets [] instead of (), now there are these indices on the top and left side. In my case on the top they are u_1,v_1,u_2,v_2 and so on. On the left side they are F_1x,F_1y,F_2x,F_2y.
Now I would like to have all the “u_i” indices in blue and all the “v_i” indices in green. The same for the left side, all the “F_ix” blue and all the “F_iy” green.
My solution looks like this and works, but if the matrix has more rows and lines this will be too much code.
bordermatrix{~ & color{blue!80!black} bf overline {u}_1
& color{green!80!black} bf overline {v}_1
& color{blue!80!black} bf overline {u}_5
& color{green!80!black} bf overline {v}_5 cr
color{blue!80!black} bf overline {F}_{1x} & 336000 & 0 & -336000 & 0 cr
color{green!80!black} bf overline {F}_{1y} & 0 & 0 & 0 & 0 cr
color{blue!80!black} bf overline {F}_{5x} & -336000 & 0 & 336000 & 0 cr
color{green!80!black} bf overline {F}_{5y} & 0 & 0 & 0 & 0 cr
}
Is there a shorter more elegant way to achieve the same result?
Using some commands can do the job easier; the example also includes an example using the blkarray
package:
documentclass{article}
usepackage{xcolor}
usepackage{amsmath}
usepackage{blkarray}
newcommandGmat[2]{%
color{green!80!black}mathbf{overline{#1}_{#2}}}
newcommandBmat[2]{%
color{blue!80!black}mathbf{overline{#1}_{#2}}}
begin{document}
[
bordermatrix{
~ & Bmat{u}{1} & Gmat{v}{1} & Bmat{u}{5} & Gmat{v}{5} cr
Bmat{F}{1x} & 336000 & 0 & -336000 & 0 cr
Gmat{F}{1y} & 0 & 0 & 0 & 0 cr
Bmat{F}{5x} & -336000 & 0 & 336000 & 0 cr
Gmat{F}{5y} & 0 & 0 & 0 & 0 cr
}
]
[
begin{blockarray}{ccccc}
~ & Bmat{u}{1} & Gmat{v}{1} & Bmat{u}{5} & Gmat{v}{5}
begin{block}{c[cccc]}
Bmat{F}{1x} & 336000 & 0 & -336000 & 0
Gmat{F}{1y} & 0 & 0 & 0 & 0
Bmat{F}{5x} & -336000 & 0 & 336000 & 0
Gmat{F}{5y} & 0 & 0 & 0 & 0
end{block}
end{blockarray}
]
end{document}
Correct answer by Gonzalo Medina on June 13, 2021
Here is a way to do that with the environments of nicematrix
.
documentclass{article}
usepackage{xcolor}
usepackage{amsmath}
usepackage{nicematrix}
begin{document}
newcommandmat[2]{mathbf{overline{#1}_{#2}}}
NiceMatrixOptions
{
code-for-first-row = ifodd value{jCol} color{blue} else color{green} fi ,
code-for-first-col = ifodd value{iRow} color{blue} else color{green} fi
}
[begin{pNiceMatrix}[first-row,first-col]
& mat{u}{1} & mat{v}{1} & mat{u}{5} & mat{v}{5}
mat{F}{1x} & 336000 & 0 & -336000 & 0
mat{F}{1y} & 0 & 0 & 0 & 0
mat{F}{5x} & -336000 & 0 & 336000 & 0
mat{F}{5y} & 0 & 0 & 0 & 0
end{pNiceMatrix}]
[begin{bNiceMatrix}[first-row,first-col]
& mat{u}{1} & mat{v}{1} & mat{u}{5} & mat{v}{5}
mat{F}{1x} & 336000 & 0 & -336000 & 0
mat{F}{1y} & 0 & 0 & 0 & 0
mat{F}{5x} & -336000 & 0 & 336000 & 0
mat{F}{5y} & 0 & 0 & 0 & 0
end{bNiceMatrix}]
end{document}
Answered by F. Pantigny on June 13, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP