Matriz aumentada con fracciones

Matriz aumentada con fracciones

Necesito componer algunas matrices aumentadas, pero algunas contienen fracciones. También necesito hacer eso con gmatrix, ya que necesito sus características.

El siguiente código se utiliza para crear la línea entre las entradas:

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

Con eso puedo crear algo como esto:

Ejemplo: matriz aumentada sin fracciones

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}

Pero cuando contiene fracciones, se parece más a esto:

Ejemplo: matriz aumentada con fracciones

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}

La línea se vuelve algo discontinua, lo que en realidad no funciona. También parece antiestético que las fracciones casi se toquen.

Espero que puedas ayudarme.

Respuesta1

Puedo ofrecerle una solución 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}

ingrese la descripción de la imagen aquí

Para fracciones en conflicto, use una nueva \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}

ingrese la descripción de la imagen aquí

Sin embargo, mi consejo es utilizar la forma con barra diagonal para las fracciones.

Respuesta2

Solo usa un regular array:

ingrese la descripción de la imagen aquí

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

Sí, debe proporcionar la especificación de la columna, pero tiene control sobre la alineación y también puede utilizar la |regla de columna predeterminada, que se extiende verticalmente sin espacios.

información relacionada