帶分數的增廣矩陣

帶分數的增廣矩陣

我需要排版一些增廣矩陣,但其中一些包含分數。我還需要使用 來做到這一點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}

是的,您必須提供列規範,但您可以控制對齊方式以及使用預設的|列規則,該規則垂直跨越而沒有間隙。

相關內容