分数を含む拡張行列

分数を含む拡張行列

いくつかの拡張行列をタイプセットする必要がありますが、その一部には分数が含まれています。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}

|はい、列の指定を行う必要がありますが、ギャップなしで垂直に広がるデフォルトの列ルールを使用するだけでなく、配置を制御することもできます。

関連情報