TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 '14 at 17:50
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 '14 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 '14 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 '14 at 9:04
up vote 15 down vote accepted

One option using TikZ:

New version:



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

\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);


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




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


  \node[circle,draw,cyan,inner sep=2pt] (a) {$#2$};
  \draw[->,shorten >= 3pt] (a.south) |- ([yshift=-9pt,xshift=-#1]a.south);


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}


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
those look like hyphens instead of minus signs in the circles. – barbara beeton Jan 21 '14 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 '14 at 17:59
@barbarabeeton Yes, they were mere hyphens. I've now fixed tha math mode. Thanks! – Gonzalo Medina Jan 21 '14 at 18:00
@OskarPersson Please see my updated answer. – Gonzalo Medina Jan 21 '14 at 18:22
@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 '14 at 18:36

Your Answer


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.