# How to insert a horizontal line in align env with some text at the end of the line

I'd like to have some math induction showing as below.(In an align environment \begin{align*}...\end{align*}) How can I have the "by addition" text at the end of the line? I tried with \cline but failed to do that.

x = 1   y = 2
-------------- by addtion
x + y = 3                z = 3
--------------------------------- by addition
x + y + z = 6


Here is what I've got so far. I also wanted the equations to be centered but I found it was hard to do.

\begin{align*}
x = 1 & y = 2 \\
\cline{1-2}
x + y = 3 & & z = 3 \\
\cline{1-3}
&x + y + z = 6& \\
\end{align*}


• Welcome to TeX.SE! Please take a moment to take our Tour! You may also want to look at what makes a good Minimal Working Example (MWE) – Tavrock Jan 31 '17 at 16:59

## 2 Answers

I created \byx{<eq1>}{<eq2>}{<via>}{<eq-sum>}, which can be nested.

\documentclass[11pt]{report}
\usepackage{amsmath,stackengine}
\newcommand\byx[4]{%
\setbox0=\hbox{$~#1\qquad#2~$}%
\setbox2=\hbox{~by #3}%
\Shortstack[c]{\copy0 \rule[2.3pt]{\wd0}{.5pt}\rlap{\copy2} $#4$}%
\hspace{\wd2}%
}
\begin{document}
$\byx{% \byx{x=1}{y=2}{addition}{x+y=3} }{z=3}{addition}{x+y+z=6}$
\end{document}


Note: You can add \setstackgap{S}{<gap>} to set the vertical gap of the stack. Default gap for \Shortstack is 3pt. The value can span the positive/negative range.

Is this what you mean? \\ will add a line break.

\documentclass{article}

\begin{document}
text...\\ \\
x = 1, y = 2
\\------------ by addition\\
x + y = 3

\end{document}


Output example:

• It seems similar. But I am trying to have it in a math environment so that I don't need to align everything by myself. – czheo Jan 31 '17 at 7:18
• Then you should be more specific in your question. Your MWE is too vague. – Jimmy Westberg Jan 31 '17 at 7:22
• Thx. Just added. – czheo Jan 31 '17 at 7:25
• But still, what are you trying to get. Left or right alignment? Please post what ever code you have so I understand what you're aiming for here. As far as I can tell my example gives you what you want (left alignment). – Jimmy Westberg Jan 31 '17 at 7:43
• You might consider reading through this post: Align equation left – Jimmy Westberg Jan 31 '17 at 7:47