1

I have a multilined equation which is aligned as follows: (schematically)

\documentclass[english]{article}
\usepackage{amsmath}
\usepackage{babel}
\begin{document}

\begin{align}
\text{Equ} &\equiv \text{first line of RHS} \;+\nonumber \\
 & \phantom{=}+\;\text{second line of RHS}\nonumber \\
 & =\text{third line of RHS} \; +\nonumber \\
 & \phantom{=} +\; \text{fourth line of RHS} 
\end{align}

\end{document}

What I'd like to achieve is a multiline box over only the third and fourth lines as follows:

enter image description here

I have tried using the \boxed{} function but this wouldn't work over multiple lines. Note: I would prefer not to box the entire four lines in this case.

Is this possible and, if so, how is it done?

Edit: (subsequent to answer by Bernard) I am having 2 difficulties implementing the pstricks solution: 1) The numbering seems to start over outside the postscript environment. 2) Equation references \eqref{} don't seem to work with \label{} inside the postscript. See output and MWE below:

problem

\documentclass[english, svgnames]{article}
\usepackage{mathtools}
\usepackage{babel}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{postscript}
\begin{align}
\text{Equ} & \equiv \text{first line of RHS} +{} \\
                         & =+\;\text{second line of RHS} \\
\pnode[-0.6em, 2.5ex]{A} & =\text{third line of RHS} + {} \\
                         & = +\; \text{fourth line of RHS}   \pnode[0.8em, -1.5ex]{B}   \label{Equ1}
\end{align}
\psframe[linejoin=1, linecolor=black](A)(B)
\end{postscript}

\begin{align}
\text{Equ2} &= \text{first line of RHS}\\
&= \text {second line of RHS}\label{Equ2}
\end{align}

Reference to Equ1: \eqref{Equ1}.  Reference to Equ2: \eqref{Equ2}.

\end{document} 
1

Shamelessly borrowed from Werner at https://tex.stackexchange.com/a/358675/4427

\documentclass{article}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{fit,tikzmark}

\begin{document}

\begin{align}
\text{Equ} &\equiv \text{first line of RHS} \nonumber \\
 &\quad + \text{second line of RHS} \nonumber \\
 \tikzmark{start1} &=\text{third line of RHS} \nonumber \\
 &\quad + \text{fourth line of RHS} \tikzmark{end1}
\end{align}
\begin{tikzpicture}[remember picture,overlay]
  \coordinate (start) at ([yshift=1.7ex]pic cs:start1);
  \coordinate (end) at ([yshift=-0.3ex]pic cs:end1);
  \node[inner sep=2pt,draw=red,fit=(start) (end)] {};
\end{tikzpicture}

\end{document}

enter image description here

0

It is easy with pstricks: place an empty node at the beginning of the third row, another empty node at the end of the fourth row, and draw the frame with opposite vertices the the two nodes. The optional argument of \pnode is an offset.

This code can be compiled with pdflatex if you set the --enable-write18 switch for MiKTeX, -shell-escape for TeX Live and MacTeX.

Alternatively, do not load auto-pst-pdf, remove the postscript environment, and compile with xelatex.

\documentclass[english, svgnames]{article}
\usepackage{mathtools}
\usepackage{babel}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{postscript}
  \begin{align}%
    \text{Equ} & ≡ \text{first line of RHS} +{} \\
                             & =+\;\text{second line of RHS} \\
    \pnode[-0.6em, 2.5ex]{A} & =\text{third line of RHS} + {} \\
                             & = +\; \text{fourth line of RHS} \pnode[0.8em, -1.5ex]{B}
  \end{align}
  \psframe[linejoin=1, linecolor=Coral](A)(B)
\end{postscript}

\end{document} 

enter image description here

Added : there seems to be problems with cross-references, which work well only in this version of the code, for use with xelatex:

\documentclass[english]{article}
 \usepackage{mathtools}
\usepackage[showframe]{geometry}
 \usepackage{babel}
\usepackage{pst-node}%
\usepackage{cleveref}

 \begin{document}

 \begin{align}%
 \text{Equ} & ≡ \text{first line of RHS} +{} \label{Equ1}\\
 & =+\;\text{second line of RHS} \\
\pnode[-0.6em, 2.5ex]{A}& =\text{third line of RHS} + {} \\
 & = +\; \text{fourth line of RHS}\label{Equ4}\pnode[0.8em, -1.5ex]{B}
 \psframe[linejoin=1](A)(B)
 \end{align}}
 \eqref{Equ1} and \cref{Equ4}

 \end{document}

enter image description here

  • 2 follow-ups: 1) I am using the TeXworks editor with MiKTeX. How does one set the \--enable-write18\ switch for MiKTeX ? 2) Is it possible to get equation numbering and use the \label{} function with this? i.e., Can one get an equation number and label the fourth line? – user143410 Jul 16 '17 at 19:11
  • For the second point: there's no problem for that (see my updated answer). Postscript acts as an overlay, and it has no dimension for TeX. To set --enable-wite18, go to Edit -> Preferences-> Typesetting tab. In the Processing tools window, select pdflatex to open Tool Configuration and add the switch to the Arguments window. – Bernard Jul 16 '17 at 19:30
  • I was able to get it to compile now, thank you. I am still having trouble with the numbering starting over and referencing equations inside the postscript (see edits to question). – user143410 Jul 16 '17 at 20:07
  • I have the same problem, and it does not seem to be linked to pstricks: I commented out all commands/environments that have something to do with it, and I still have the same message over and over: ` LaTeX Warning: Reference Equ1' on page 1 undefined on input line 49.LaTeX Warning: Reference Equ2' on page 1 undefined on input line 49.` However my editor sees them. – Bernard Jul 16 '17 at 20:50
  • I appreciate you troubleshooting the cross-references and I upvoted your answer. My rep is too low for it to affect the public score count yet, though. – user143410 Jul 17 '17 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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