我需要排版一些增广矩阵,但其中一些包含分数。我也需要用 来做这件事gmatrix
,因为我需要它的功能。
以下代码用于在条目之间创建线:
\newcommand{\mline}{%
\hspace{-\arraycolsep}%
\strut\vrule
\hspace{-\arraycolsep}%
}
通过它我可以创建类似这样的内容:
代码:
\begin{align}
\begin{gmatrix}[p]
1 & 2 & 3 & \mline & 40 \\
2 & 3 & 4 & \mline & 500 \\
3 & 4 & 5 & \mline & 6000
\end{gmatrix}
\end{align}
但当它包含分数时,它看起来更像这样:
代码:
\begin{align}
\begin{gmatrix}[p]
1 & 2 & \frac{1}{3} & \mline & 40 \\
2 & 3 & \frac{1}{4} & \mline & 500 \\
3 & 4 & 5 & \mline & \frac{1}{6}
\end{gmatrix}
\end{align}
线条有点虚线,实际上不太好用。分数几乎相接,看起来也不美观。
我希望你能帮助我。
答案1
我可以为您提供手动修复:
\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}
% patch gauss macros for doing their work in `align'
% and other amsmath environments; see
% http://tex.stackexchange.com/questions/146532/
\usepackage{etoolbox}
\makeatletter
\patchcmd\g@matrix
{\vbox\bgroup}
{\vbox\bgroup\normalbaselines}% restore the standard baselineskip
{}{}
\makeatother
\newcommand{\mline}[1][0pt]{%
\hspace{-\arraycolsep}%
\ifdim#1>0pt
\dimen0=\ht\strutbox \dimen2=\dimen0
\advance\dimen0 #1\relax
\ht\strutbox=\dimen0
\fi
\smash{\strut\vrule} % the `\vrule` is as high and deep as a strut
% since assignments to \ht\strutbox are global, we restore the height
\ifdim#1>0pt
\ht\strutbox=\dimen2
\fi
\hspace{-\arraycolsep}%
}
\begin{document}
\[
\begin{gmatrix}[p]
1 & 2 & \mline & 3 \\
4 & 5 & \mline & 6 \\
7 & 8 & \mline[2pt] & \frac{1}{6}
\rowops
\swap{0}{1}
\mult{0}{\cdot 7}
\add[5]{1}{2}
\end{gmatrix}
\]
\end{document}
对于有冲突的分数,请使用新的\gfrac
宏
\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}
% patch gauss macros for doing their work in `align'
% and other amsmath environments; see
% http://tex.stackexchange.com/questions/146532/
\usepackage{etoolbox}
\makeatletter
\patchcmd\g@matrix
{\vbox\bgroup}
{\vbox\bgroup\normalbaselines}% restore the standard baselineskip
{}{}
\makeatother
\newcommand{\gfrac}[2]{\frac{\smash[b]{\mathstrut}#1}{\smash[t]{\mathstrut}#2}}
\newcommand{\BAR}[1][0pt]{%
\hspace{-\arraycolsep}%
\ifdim#1>0pt
\dimen0=\ht\strutbox \dimen2=\dimen0
\advance\dimen0 #1\relax
\ht\strutbox=\dimen0
\fi
\smash{\strut\vrule} % the `\vrule` is as high and deep as a strut
% since assignments to \ht\strutbox are global, we restore the height
\ifdim#1>0pt
\ht\strutbox=\dimen2
\fi
\hspace{-\arraycolsep}%
}
\begin{document}
\[
\begin{gmatrix}[p]
1 & \gfrac{1}{3} & \BAR & 3 \\
4 & \gfrac{1}{4} & \BAR[4pt] & 6 \\
7 & 8 & \BAR[2pt] & \frac{1}{6}
\rowops
\swap{0}{1}
\mult{0}{\cdot 7}
\add[5]{1}{2}
\end{gmatrix}
\]
\end{document}
不过,我的建议是使用斜线形式来表示分数。
答案2
只需使用常规array
:
\documentclass{article}
\begin{document}
\[
\left(\begin{array}{@{} r r r | r @{}}
1 & 2 & 3 & 40 \\
2 & 3 & 4 & 500 \\
3 & 4 & 5 & 6000
\end{array}\right)
\qquad
\renewcommand{\arraystretch}{1.2}% http://tex.stackexchange.com/a/31704/5764
\left(\begin{array}{@{} r r r | r @{}}
1 & 2 & \frac{1}{3} & 40 \\
2 & 3 & \frac{1}{4} & 500 \\
3 & 4 & 5 & \frac{1}{6}
\end{array}\right)
\]
\end{document}
是的,您必须提供列规范,但您可以控制对齐方式以及使用默认|
列规则,该规则垂直跨越而没有间隙。