TransWikia.com

How to format a matrix system of equations in LATEX

TeX - LaTeX Asked on August 11, 2021

I currently have the following code for a system of equations:

documentclass{article}

usepackage{amsmath}
usepackage{etoolbox}

    newcommand{dpartial}[2]{frac{partial #1}{partial #2}}

    AtBeginEnvironment{bmatrix}{everymath{displaystyle}} % displaystyle systems of equations

begin{document}
 begin{equation}
    begin{bmatrix} 
        mdpartial{u}{T} & mdpartial{u}{p}  
        -mleft(Tdpartial{R}{T} + Rright) & V - mTdpartial{R}{p} 
    end{bmatrix}
    %
    begin{bmatrix}
        dot{T}  
        dot{p} 
    end{bmatrix} = 
    %
    begin{bmatrix}
        dot{Q} - pdot{V} + dot{m}(h-u) - mdpartial{u}{phi}dot{phi}  
        dot{m}RT + mTdpartial{R}{phi}dot{phi} - pdot{V} 
    end{bmatrix}
    end{equation}
end{document}

However, this is the result:

enter image description here

Therefore, my question is whether there is a way to format the system of equations, such that the vector containing the derivatievs of T and p can have the same height as its adjacent matrices.

Thanks for your help in advance.

2 Answers

By adding vphantom{dpartial{u}{p}} to elements of vector:

enter image description here

documentclass{article}

usepackage{amsmath}
    newcommand{dpartial}[2]{frac{partial #1}{partial #2}}
usepackage{etoolbox}
    AtBeginEnvironment{bmatrix}{everymath{displaystyle}} % displaystyle systems of equations

begin{document}
 begin{equation}
    begin{bmatrix}
        mdpartial{u}{T} & mdpartial{u}{p} 
        -mleft(Tdpartial{R}{T} + Rright) & V - mTdpartial{R}{p}
    end{bmatrix}
    %
    begin{bmatrix}
        dot{T}vphantom{dpartial{u}{p}} 
        dot{p}vphantom{dpartial{u}{p}}
    end{bmatrix} =
    %
    begin{bmatrix}
        dot{Q} - pdot{V} + dot{m}(h-u) - mdpartial{u}{phi}dot{phi}  
        dot{m}RT + mTdpartial{R}{phi}dot{phi} - pdot{V}
    end{bmatrix}
    end{equation}
end{document}

Addendum: Considering to @Mico comment, you will get better looking matrices and vector by inserting some vertical space between their rows. This you can achieve on many ways, for example:

  • by terminate rows with [2ex]
  • by inserting addlinespace determined in the booktabs package:
documentclass{article}
usepackage{booktabs}

usepackage{amsmath}
    newcommand{dpartial}[2]{frac{partial #1}{partial #2}}
usepackage{etoolbox}
    AtBeginEnvironment{bmatrix}{everymath{displaystyle}} % displaystyle systems of equations

begin{document}
 begin{equation}
    begin{bmatrix}
        mdpartial{u}{T} & mdpartial{u}{p} 
        addlinespace
        -mbiggl(Tdpartial{R}{T} + Rbiggr) & V - mTdpartial{R}{p}
    end{bmatrix}
    %
    begin{bmatrix}
        dot{T}vphantom{dpartial{u}{p}} 
        addlinespace
        dot{p}vphantom{dpartial{u}{p}}
    end{bmatrix} =
    %
    begin{bmatrix}
        dot{Q} - pdot{V} + dot{m}(h-u) - mdpartial{u}{phi}dot{phi}  
        addlinespace
        dot{m}RT + mTdpartial{R}{phi}dot{phi} - pdot{V}
    end{bmatrix}
    end{equation}
end{document}

enter image description here

  • by use of makegapedcells defined in the makecell package:
documentclass{article}
usepackage{makecell}

usepackage{amsmath}
    newcommand{dpartial}[2]{frac{partial #1}{partial #2}}
usepackage{etoolbox}
    AtBeginEnvironment{bmatrix}{everymath{displaystyle}} % displaystyle systems of equations

begin{document}
 begin{equation}
setcellgapes{5pt}
makegapedcells
    begin{bmatrix}
        mdpartial{u}{T} & mdpartial{u}{p} 
        -mbiggl(Tdpartial{R}{T} + Rbiggr) & V - mTdpartial{R}{p}
    end{bmatrix}
    %
    begin{bmatrix}
        dot{T}vphantom{dpartial{u}{p}} 
        dot{p}vphantom{dpartial{u}{p}}
    end{bmatrix} =
    %
    begin{bmatrix}
        dot{Q} - pdot{V} + dot{m}(h-u) - mdpartial{u}{phi}dot{phi}  
        dot{m}RT + mTdpartial{R}{phi}dot{phi} - pdot{V}
    end{bmatrix}
    end{equation}
end{document}

enter image description here

Correct answer by Zarko on August 11, 2021

With the latest version of nicematrix (v. 5.10 of 2021-02-05), you can construct an array and add the brackets after with the built-in command SubMatrix. You don't need vphantom.

documentclass{article}
usepackage{nicematrix}
newcommand{dpartial}[2]{frac{partial #1}{partial #2}}

begin{document}
begin{equation}
everymath{displaystyle}
begin{NiceMatrix}
mdpartial{u}{T} & mdpartial{u}{p} & dot{T}   
-mleft(Tdpartial{R}{T} + Rright) & V - mTdpartial{R}{p} & dot{p} 
CodeAfter 
SubMatrix[{1-1}{2-2}]
SubMatrix[{1-3}{2-3}]
end{NiceMatrix}
=
begin{bmatrix}
dot{Q} - pdot{V} + dot{m}(h-u) - mdpartial{u}{phi}dot{phi}  
dot{m}RT + mTdpartial{R}{phi}dot{phi} - pdot{V} 
end{bmatrix}
end{equation}
end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

enter image description here

Answered by F. Pantigny on August 11, 2021

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