8

Is there a way to create the doublesided arrow that goes from row 2 to row 4 to indicate a rowswitch? Thank you.

\documentclass{report}
\usepackage{amsmath, amssymb, graphics, setspace}
\begin{document}
    \begin{equation}\notag
    \left[
        \begin{array}{cccc | c}
             1 & 1 & 1 & 2 & 0\\
             2 & 0 & -2 & 2 & 0\\
             2 & 1 & 0 & 3 & 0\\
            -1 & 2 & 5 & 1 & 0\\
        \end{array}
    \right]
        \begin{array}{cc}
              &\\
             from\ here &\\
              &\\
             to\ here &\\
        \end{array}
    \end{equation}
\end{document}

Edit: Thank you for all the great responses! enter image description here

3
  • 2
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Nov 25, 2016 at 15:20
  • (basically, it's easier for us to help you if we do not have to type everything, including the matrix)
    – ebosi
    Nov 25, 2016 at 15:41
  • it should be up now Nov 25, 2016 at 16:10

3 Answers 3

8

You can use the gauss package, with some fixes:

\documentclass{report}
\usepackage{amsmath, gauss}
\usepackage{etoolbox}

% see http://tex.stackexchange.com/a/146730/4427
\makeatletter
\patchcmd\g@matrix
 {\vbox\bgroup}
 {\vbox\bgroup\normalbaselines}% restore the standard baselineskip
 {}{}
\makeatother

\newcommand{\BAR}{%
  \hspace{-\arraycolsep}%
  \strut\vrule % the `\vrule` is as high and deep as a strut
  \hspace{-\arraycolsep}%
}


\begin{document}

\begin{equation*}
\begin{gmatrix}[b]
1  & 1 &  1 & 2 & \BAR & 0\\
2  & 0 & -2 & 2 & \BAR & 0\\
2  & 1 &  0 & 3 & \BAR & 0\\
-1 & 2 &  5 & 1 & \BAR & 0
\rowops
\swap{1}{3}% the count is from 0
\end{gmatrix}
\end{equation*}

\end{document}

Note that you should use equation* rather than equation with \notag.

enter image description here

0
7

You can use tikz with its remember picture and overlay options.

enter image description here

\documentclass{report}
\usepackage{amsmath, amssymb, graphics, setspace}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{every picture/.append style={remember picture},
         na/.style={baseline=-0.6ex}}
\begin{document}
    \begin{equation}\notag
    \left[
        \begin{array}{cccc | c}
             1 & 1 & 1 & 2 & 0\\
             2 & 0 & -2 & 2 & 0\tikz[na]\coordinate(a);\\
             2 & 1 & 0 & 3 & 0\\
            -1 & 2 & 5 & 1 & 0\tikz[na]\coordinate(b);\\
        \end{array}
    \right]
    \end{equation}
    % 0.4 cm is the distance between the coordinates inside the square brackets and the arrow tips outside.
    % 0.3 cm is the length of the horizontal lines.
    \tikz[overlay]\draw[thick,<->] ($(a)+(0.4,0)$) -- +(0.3,0) |- ($(b)+(0.4,0)$);
\end{document}
0
5

Here are two other solutions: one with pstricks and auto-pst-pdf to compile with pdflatex (provided you set -shell-escape switch (TeX Live, MacTeX) or --enable-write18 (MiKTeX) for the compiler). The other uses the dedicated package gauss which defines a gmatrix environment, with customisable left and right delimiters.

\documentclass{report}
\usepackage{amsmath, amssymb, graphics, setspace}
\usepackage{pst-node, auto-pst-pdf} %

\usepackage{gauss} %
\newmatrix{|\;}{]}{vb}
\newmatrix{[}{.\,}{lb}
\setlength\rowarrowsep{-3pt}

\begin{document}

\[ \begin{postscript}
  \left[ \begin{array}{@{\:}cccc|c @{\:}}%
    1 & 1 & 1 & 2 & 0\\
    2 & 0 & -2 & 2 & 0\pnode[0,0.8ex]{T}\\
    2 & 1 & 0 & 3 & 0\\
    -1 & 2 & 5 & 1 & 0\pnode[0,0.8ex]{B}
  \end{array} \right]
  \ncbar[linewidth=0.6pt, arrows=<->, nodesep=7pt, arrowinset=0.12, linejoin=1,arm=0.25]{T}{B}
  \end{postscript}
\]
\[ \begin{gmatrix}[lb]
  1 & 1 & 1 & 2 \\
  2 & 0 & -2 & 2 \\
  2 & 1 & 0 & 3\\
  -1 & 2 & 5 & 1 \end{gmatrix} \begin{gmatrix}[vb] %
    0\\
    0 \\
    0\\
    0
    \rowops
    \swap{1}{3}
  \end{gmatrix} \]%

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .