Matriz aumentada com frações

Matriz aumentada com frações

Preciso compor algumas matrizes aumentadas, mas algumas delas contêm frações. Também preciso fazer isso gmatrix, pois preciso de seus recursos.

O código a seguir é usado para criar a linha entre as entradas:

\newcommand{\mline}{%
  \hspace{-\arraycolsep}%
  \strut\vrule
  \hspace{-\arraycolsep}%
}

Com isso posso criar algo assim:

Exemplo: matriz aumentada sem frações

Código:

\begin{align} 
    \begin{gmatrix}[p] 
        1 & 2 & 3 & \mline & 40 \\
        2 & 3 & 4 & \mline & 500 \\
        3 & 4 & 5 & \mline & 6000
    \end{gmatrix} 
\end{align}

Mas quando contém frações, fica mais parecido com isto:

Exemplo: Matriz Aumentada com Frações

Código:

\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}

A linha fica meio tracejada, o que realmente não funciona. Também parece antiestético que as frações quase se toquem.

Espero que você possa me ajudar.

Responder1

Posso oferecer uma correção manual:

\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}

insira a descrição da imagem aqui

Para frações conflitantes, use uma nova \gfracmacro

\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}

insira a descrição da imagem aqui

No entanto, meu conselho é usar a forma cortada para frações.

Responder2

Basta usar um normal array:

insira a descrição da imagem aqui

\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}

Sim, você precisa fornecer a especificação da coluna, mas tem controle sobre o alinhamento e também usa a |regra de coluna padrão, que se estende verticalmente sem lacunas.

informação relacionada