我想获得一个具有良好对齐矩阵的线性状态空间方程。使用的基本解决方案array
确实是完美的(参见公式 (1)。
现在,使用nicematrix
(获得各处相同宽度的列),我接近预期的结果(参见公式(2),编译两次)。
现在,为了很好地对齐所有内容,最后一件事就是修复分隔符的粗细,但该怎么做呢?(顺便问一下,为什么等式(2)之后的“Now”之前有一个空格?)
梅威瑟:
\documentclass{article}
\usepackage{mathtools,nicematrix}
\begin{document}
I would like to obtain a linear state-space equation with nicely-aligned matrices. A basic solution using array is indeed perfectible:
\begin{align}
\begin{dcases}
\dot x=
\left[\begin{array}{cc}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{array}\right]
x+\left[\begin{array}{c}
0\\
\dfrac{1}{LC}
\end{array}\right]
u\\
y=\left[\begin{array}{cc}
1 &0
\end{array}\right]
x+\left[\begin{array}{c}
0
\end{array}\right] u
\end{dcases}
\end{align}
Now, using nicematrix (to obtain same-width columns everywhere), I come close to the expected result (compile twice):
\begin{NiceMatrixBlock}[auto-columns-width]
\begin{align}
\begin{dcases}
\dot x=
\begin{bNiceMatrix}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{bNiceMatrix}
x+\begin{bNiceMatrix}
0\\
\dfrac{1}{a}
\end{bNiceMatrix}
u\\
y=\begin{bNiceMatrix}
1 &0
\end{bNiceMatrix}
x+\begin{bNiceMatrix}
0
\end{bNiceMatrix} u
\end{dcases}
\end{align}
\end{NiceMatrixBlock}
Now, to nicely align everything, the last thing to do is to fix the thickness of delimiters, but how to do it? (And, by the way, why is there a space before ``Now'' after equation (2)?)
\end{document}
编辑:以下是我所使用的,感谢@F.Pantigny。
\documentclass{article}
\usepackage{amsmath,calc}
\usepackage{mathtools,nicematrix}
\NewDocumentEnvironment{MyMatrix}{}
{\begin{NiceArrayWithDelims}{[}{]}{*{\value{MaxMatrixCols}}{c}}}
{\end{NiceArrayWithDelims}}
\begin{document}
I would like to obtain a linear state-space equation with nicely-aligned matrices. A basic solution using array is indeed perfectible:
\begin{align}
\begin{dcases}
\dot x=
\left[\begin{array}{cc}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{array}\right]
x+\left[\begin{array}{c}
0\\
\dfrac{1}{LC}
\end{array}\right]
u\\
y=\left[\begin{array}{cc}
1 &0
\end{array}\right]
x+\left[\begin{array}{c}
0
\end{array}\right] u
\end{dcases}
\end{align}
Using the \verb=nicematrix= package (to obtain same-width columns everywhere), I come close to the expected result (compile twice):
%
\begin{NiceMatrixBlock}[auto-columns-width]
\begin{align}
\begin{dcases}
\dot x=
\begin{MyMatrix}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{MyMatrix}
x+\begin{MyMatrix}
0\\
\dfrac{1}{a}
\end{MyMatrix}
u\\
\parbox{\widthof{$\dot x$}}{$y$}=\begin{MyMatrix}
1 &0
\end{MyMatrix}
x+\begin{MyMatrix}
0
\end{MyMatrix} u
\end{dcases}
\end{align}
\end{NiceMatrixBlock}%
%
Now, with \verb=\NiceMatrixOptions{delimiters/max-width}=:
%
\begin{NiceMatrixBlock}[auto-columns-width]
\NiceMatrixOptions{delimiters/max-width}
\begin{align}
\begin{dcases}
\dot x=
\begin{MyMatrix}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{MyMatrix}
x+\begin{MyMatrix}
0\\
\dfrac{1}{a}
\end{MyMatrix}
u\\
\parbox{\widthof{$\dot x$}}{$y$}=\begin{MyMatrix}
1 &0
\end{MyMatrix}
x+\begin{MyMatrix}
0
\end{MyMatrix} u
\end{dcases}
\end{align}
\end{NiceMatrixBlock}%
%
This is \emph{almost exactly} what I want, even though the difference between brackets still hurts my eyes a little bit (I'm a freak) and it is not \emph{perfectly} aligned (I'm definitely a freak). Well, I'll give it a go for now, I might get used to it.
Note that in the version with \verb=\lgroup= and \verb=\rgoup= instead of brackets -- which allows for perfect alignment --, I find that the delimiters are too noticeable (didn't I told you I was a freak?):
%
\begin{NiceMatrixBlock}[auto-columns-width]
\begin{align}
\begin{dcases}
\dot x=
\begin{NiceArrayWithDelims}{\lgroup}{\rgroup}{cc}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{NiceArrayWithDelims}
x+\begin{NiceArrayWithDelims}{\lgroup}{\rgroup}{cc}
0\\
\dfrac{1}{a}
\end{NiceArrayWithDelims}
u\\
\parbox{\widthof{$\dot x$}}{$y$}=\begin{NiceArrayWithDelims}{\lgroup}{\rgroup}{cc}
1 &0\\
\end{NiceArrayWithDelims}
x+\begin{NiceArrayWithDelims}{\lgroup}{\rgroup}{cc}
0
\end{NiceArrayWithDelims} u
\end{dcases}
\end{align}
\end{NiceMatrixBlock}%
\end{document}
答案1
为什么不使用\lgroup
and\rgroup
而使用[
and ]
?
\documentclass{article}
\usepackage{mathtools,nicematrix}
\NewDocumentEnvironment{MyMatrix}{}
{\begin{NiceArrayWithDelims}{\lgroup}{\rgroup}{*{\value{MaxMatrixCols}}{c}}}
{\end{NiceArrayWithDelims}}
\begin{document}
\begin{NiceMatrixBlock}[auto-columns-width]
\begin{align}
\begin{dcases}
\dot x=
\begin{MyMatrix}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{MyMatrix}
x+\begin{MyMatrix}
0\\
\dfrac{1}{a}
\end{MyMatrix}
u\\
y=\begin{MyMatrix}
1 &0
\end{MyMatrix}
x+\begin{MyMatrix}
0
\end{MyMatrix} u
\end{dcases}
\end{align}
\end{NiceMatrixBlock}
\end{document}
delimiters/max-width
您也可以尝试使用的键nicematrix
。
\documentclass{article}
\usepackage{mathtools,nicematrix}
\begin{document}
\begin{NiceMatrixBlock}[auto-columns-width]
\NiceMatrixOptions{delimiters/max-width}
\begin{align}
\begin{dcases}
\dot x=
\begin{bNiceMatrix}
0 &1\\
-\dfrac{1}{xyz} &\dfrac{a}{b}
\end{bNiceMatrix}
x+\begin{bNiceMatrix}
0\\
\dfrac{1}{a}
\end{bNiceMatrix}
u\\
y=\begin{bNiceMatrix}
1 &0
\end{bNiceMatrix}
x+\begin{bNiceMatrix}
0
\end{bNiceMatrix} u
\end{dcases}
\end{align}
\end{NiceMatrixBlock}
\end{document}
答案2
手工制作,但满足要求。
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{graphicx}
\newlength{\templen}
\begin{document}
I would like to obtain a linear state-space equation with
nicely-aligned matrices. A basic solution using array is
indeed perfectible:
\[
% local macros to reduce clutter
\settowidth{\templen}{$-\dfrac{1}{xyz}$}
\newcommand{\?}[2]{%
\begin{array}{@{}*{#1}{w{c}{\templen}@{}}}#2\end{array}%
}
\newcommand{\1}[1]{\scalebox{2}[1]{$#1$}}
\left\lbrace
\begin{aligned}
\dot{x} &= \left[\?{2}{\hphantom{-}0 & 1 \\[0.5ex] -\dfrac{1}{xyz} & \dfrac{a}{b}}\right]
+ \left[\?{1}{0 \\[0.5ex] \dfrac{1}{LC\vphantom{y}}}\right]u
\\[3ex]
y &= \,\1[\?{2}{1 & 0}\1]\,+\1[\?{1}{0}\1]\,\,u
\end{aligned}
\right.
\]
I would like to obtain a linear state-space equation with
nicely-aligned matrices. A basic solution using array is
indeed perfectible.
\end{document}