2

I want to put a box around a equation spreading multiple lines. Minimum working example:

 \documentclass{article}
 \usepackage[utf8]{inputenc}
 %\usepackage{amsmath}
 \usepackage{comment}
 \usepackage{mathtools, cuted}
 %\usepackage{natbib}
 \usepackage{amssymb}
 \usepackage{breqn}
 %\usepackage{amsthm}
 \usepackage{hyperref}
 %\bibliographystyle{plain}
 %\newtheorem{thm}{Theorem}[section]
 %\newtheorem{lem}[thm]{Lemma}
 %\newtheorem{cor}[thm]{Corollary}
 \newtheorem{rmk}{Remark}
 %\newtheorem{def}[rmk]{Definition}
 %\newtheorem*{proof}{Proof}
 \usepackage{amsmath}
 \usepackage{mathtools}
 \usepackage{enumitem}

  %\usepackage[dvips]{epsfig}    % or this line, depending on which
                           % you prefer.
  \makeatletter
  \DeclareRobustCommand{\qed}{%
  \ifmmode % if math mode, assume display: omit penalty etc.
  \else \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
  \fi
  \quad\hbox{\qedsymbol}}
  \newcommand{\openbox}{\leavevmode
  \hbox to.77778em{%
  \hfil\vrule
  \vbox to.675em{\hrule width.6em\vfil\hrule}%
  \vrule\hfil}}
  \newcommand{\qedsymbol}{\openbox}
  \newenvironment{proof}[1][\proofname]{\par
  \normalfont
  \topsep6\p@\@plus6\p@ \trivlist
  \item[\hskip\labelsep\itshape
  #1.]\ignorespaces
   }{%
  \qed\endtrivlist
  }
   \newcommand{\proofname}{Proof}
   \makeatother

   \begin{document}
   \begin{align}
    &\frac{1}{\min_i \sum_j e^{c(i,j)}p(j|i)}\sum_{i,j=1}^s                                      e^{c(i,j)}p(j|i)x_i y_j \left[c(i,j) + \ln p(j|i)-\ln \sqrt{\pi_i} - 
   \ln\phi^{k(i)}(i) -\ln\left(\sum_{l=1}^s \phi^{k(i)}(l)\pi_la_{lj}         \right)+\ln \sqrt{\pi_j}+ \right. \nonumber \\
   & \left. \ln\left(\sum_{m=1}^s{\phi^{k(i)}(m)}^2\pi_m\right)\right]        \label{first}.
   \end{align}
   \end{document} 
4

Something like this?

enter image description here

 \documentclass{article}

\usepackage[margin=0.5in]{geometry}
\usepackage{empheq}


   \begin{document}
   \begin{empheq}[box=\fbox]{align}
    &\frac{1}{\min_i \sum_j e^{c(i,j)}p(j|i)}\sum_{i,j=1}^s                                      e^{c(i,j)}p(j|i)x_i y_j \left[c(i,j) + \ln p(j|i)-\ln \sqrt{\pi_i} - 
   \ln\phi^{k(i)}(i) -\ln\left(\sum_{l=1}^s \phi^{k(i)}(l)\pi_la_{lj}         \right)+\ln \sqrt{\pi_j}+ \right. \nonumber \\
   & \left. \ln\left(\sum_{m=1}^s{\phi^{k(i)}(m)}^2\pi_m\right)\right]        \label{first}.
   \end{empheq}
   \end{document}
2

In this very particular case amsmath (or mathtools, which loads it) is enough: basically replace

\begin{align}
first line \nonumber \\
second line \nonumber \\
third line \label{whatever}
\end{align}

by

\begin{equation} \label{whatever}
\boxed{
\begin{aligned}[b]
first line \\
second line \\
third line
\end{aligned}}
\end{equation}

In your case (I had to break the equation in more lines, it was far too wide)

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{equation}\label{first}
\boxed{
\begin{aligned}[b]
\frac{1}{\min_i \sum_j e^{c(i,j)}p(j|i)} & \sum_{i,j=1}^s e^{c(i,j)}p(j|i)x_i y_j \\
\times \biggl[&c(i,j) + \ln p(j|i)-\ln \sqrt{\pi_i} \\
&- \ln\phi^{k(i)}(i) -\ln\biggl(\sum_{l=1}^s \phi^{k(i)}(l)\pi_la_{lj} \biggr)+\ln \sqrt{\pi_j}  \\
&+ \ln\biggl(\sum_{m=1}^s{\phi^{k(i)}(m)}^2\pi_m\biggr)\biggr] .
\end{aligned}}
\end{equation}
\end{document}

enter image description here

The exact alignment points are of course somewhat a matter of taste; it's the boxing I wanted to show...

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.