Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I write a linear equation system that uses circles and arrows to indicate what should be added on each line.

This is what I have so far:

$S = \begin{cases}
    x_1+2x_2 - 2x_3 = 1 \\
    2x_1 - x_2 + x_3 = 3 \\
    x_1 + 3x_2 + x_3 = 1
\end{cases}$

enter image description here

And it should look like this:

enter image description here

share|improve this question
    
This is related (tex.stackexchange.com/questions/140529/…) only insofar as placing such notes below equations. Placing notes to the side presents a slightly different challenge. –  Steven B. Segletes Jan 21 at 17:50
1  
Do you want to illustrate row operations in the system of equations? Then the gauss package might do the job: ctan.org/pkg/gauss –  Robert Jan 21 at 21:40
    
@Robert How can I write what I want in Gauss? I can only find how to write parentheses and not S = {... –  Oskar Jan 22 at 9:45
    
You can define a new matrix with only the left delimiter {: \newmatrix{\{}{.}{A} and use it with \begin{gmatrix}[A] ... \end{gmatrix} Maybe I was too hasty when I suggested gauss: It's only for matrices and I don't think it's possible to write equations. Sorry about that! –  Robert Jan 23 at 9:04

1 Answer 1

up vote 13 down vote accepted

One option using TikZ:

New version:

\documentclass{article}
\usepackage{amsmath}
\usepackage{systeme}
\usepackage{tikz}

\newcounter{tmp}

\newcommand\tikzmark[1]{%
\tikz[remember picture,baseline=-0.65ex]
  \node[inner sep=0,outer sep=0] (#1){};%
}

\newcommand\mess[4][25pt]{%
\stepcounter{tmp}%
\begin{tikzpicture}[remember picture,overlay,>=latex,xshift=#1,cyan]
  \node[circle,draw,cyan,inner sep=2pt] at ([xshift=#1]#2) (a\thetmp) {$#4$};
  \draw[->] (a\thetmp.south) |- (#3);
\end{tikzpicture}%
}

\begin{document}

\[
S = 
\systeme{x_1+2x_2 - 2x_3 = 1 \tikzmark{a},
    2x_1 - x_2 + x_3 = 3 \tikzmark{b},
    x_1 + 3x_2 + x_3 = 1 \tikzmark{c}}
\]

\mess{a}{b}{-2}
\mess[55pt]{a}{c}{-1}

\end{document}

Explanation:

First, you place some marks for the relevant lines using \tikzmark, then you use the \mess command to add the circles with their arrows; the three mandatory arguments for \mess are the string for the initial mark, the string for the final mark, and the text to be used inside the circle. The optional argument gives control over the length of the horizontal separation.

Notice also the use of the systeme package, so that the system of equations gets nicely typeset.

Since the code requires some internal calculation, two or three runs will be needed for the elements to stabilize.

enter image description here

First version

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand\mess[2][20pt]{%
\begin{tikzpicture}[overlay,>=latex,yshift=22pt,xshift=#1,cyan]
  \node[circle,draw,cyan,inner sep=2pt] (a) {$#2$};
  \draw[->,shorten >= 3pt] (a.south) |- ([yshift=-9pt,xshift=-#1]a.south);
\end{tikzpicture}%
}

\begin{document}

\[
S = \begin{cases}
    \phantom{0}x_1+2x_2 - 2x_3 = 1 \\
    2x_1 - \phantom{0}x_2 + \phantom{0}x_3 = 3 \mess{-2}\\
    \phantom{0}x_1 + 3x_2 + \phantom{0}x_3 = 1 \mess[40pt]{-1}
\end{cases}
\]

\end{document}

enter image description here

The mandatory argument for \mess will be written in the circular node; the optional argument allows control over the length of the horizontal part of the arrow.

share|improve this answer
1  
those look like hyphens instead of minus signs in the circles. –  barbara beeton Jan 21 at 17:56
    
What should I do if I want one from the first to the second row and one from the first to the third row? –  Oskar Jan 21 at 17:59
    
@barbarabeeton Yes, they were mere hyphens. I've now fixed tha math mode. Thanks! –  Gonzalo Medina Jan 21 at 18:00
1  
@OskarPersson Please see my updated answer. –  Gonzalo Medina Jan 21 at 18:22
1  
@OskarPersson Glad I could help! By the way, I made a new update to my answer introducing some improvements and making some simplifications to the code. –  Gonzalo Medina Jan 21 at 18:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.