![等式两边的矩阵行对齐,带规则](https://linux22.com/image/291973/%E7%AD%89%E5%BC%8F%E4%B8%A4%E8%BE%B9%E7%9A%84%E7%9F%A9%E9%98%B5%E8%A1%8C%E5%AF%B9%E9%BD%90%EF%BC%8C%E5%B8%A6%E8%A7%84%E5%88%99.png)
我有以下代码来生成矩阵方程,在 LHS 矩阵上,添加了一些规则,导致 RHS 对应的行未对齐(垂直)。如果我坚持使用当前代码,如何调整 RHS 矩阵中的细微 vspace?还有没有办法调整规则的灰度(使它们不那么分散注意力)?
\documentclass{article}
\usepackage{mathtools}
% add vertical lines
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother
\usepackage{booktabs} % add horizontal lines
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}
\begin{document}
\begin{equation}
\begin{bmatrix}[cc|c|c|c|c]
\phantom{abcd} & \phantom{ } & & & 0 & \phantom{abcd} \\
& & & & 0 & \\
& & & & \cdots & \\
& & & & \cdots & \\ \cmidrule(lr){1-6}
& & a^{*}_{ts} & & 1 & \\ \cmidrule(lr){1-6}
& & & & 0 & \\
& & & & \cdots & \\
& & & & \cdots & \\
& & & & \cdots & \\
& & & & 0 & \\
& & & & 0 & \\ \cmidrule(lr){1-6}
& & \tikzmark{enter}{$c^{*}_s$} & & \tikzmark{leaving}{$c^{*}_t$} & \\
\end{bmatrix}
=
\begin{bmatrix}
\phantom{four} \\
\\
\\
\\
b^{*}_t \\
\\
\\
\\
\\
\\
\\
\\
-v \\
\end{bmatrix}
\end{equation}
\tikz[overlay,remember picture] {
\draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
\draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}
答案1
在这种情况下,array
更加灵活:
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}
\begin{document}
\begin{equation}
\left[
\begin{array}{@{\qquad}|c|@{\quad}|c|@{\qquad}}
& 0 \\
& 0 \\
& \cdots \\
& \cdots \\ \hline
a^{*}_{ts} & 1 \\ \hline
& 0 \\
& \cdots \\
& \cdots \\
& \cdots \\
& 0 \\
& 0 \\ \hline
\tikzmark{enter}{$c^{*}_s$} & \tikzmark{leaving}{$c^{*}_t$}
\end{array}
\right]
=
\left[\begin{array}{@{}c@{}}
\\ \\ \\ \\
b^{*}_t \\
\\ \\ \\ \\ \\ \\
-v
\end{array}\right]
\end{equation}
\tikz[overlay,remember picture] {
\draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
\draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}
如果您还加载xcolor
和colortbl
,则可以更改规则的色调:
\documentclass{article}
\usepackage{mathtools,xcolor,colortbl}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}
\begin{document}
\begin{equation}
\arrayrulecolor{black!30}
\left[
\begin{array}{@{\qquad}|c|@{\quad}|c|@{\qquad}}
& 0 \\
& 0 \\
& \cdots \\
& \cdots \\ \hline
a^{*}_{ts} & 1 \\ \hline
& 0 \\
& \cdots \\
& \cdots \\
& \cdots \\
& 0 \\
& 0 \\ \hline
\tikzmark{enter}{$c^{*}_s$} & \tikzmark{leaving}{$c^{*}_t$}
\end{array}
\right]
=
\left[\begin{array}{@{}c@{}}
\\ \\ \\ \\
b^{*}_t \\
\\ \\ \\ \\ \\ \\
-v
\end{array}\right]
\arrayrulecolor{black}
\end{equation}
\tikz[overlay,remember picture] {
\draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
\draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}
最后必须重新建立颜色,因为\arrayrulecolor
这是一个全局声明。