7

I need to box part of an equation, but I need the frame to be open one side. In the following MWE I would need the left part of the equation not to have the right frame of the box and the right part of the equation not to have the left frame of the box.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\begin{document}
This is my equation $\boxed{q_1^{\ast}}=\dfrac{26-2\cdot 1 -4\cdot 2}{2\cdot 1}=\boxed{8}$
\end{document}
Dom
  • 301

1 Answers1

6

The following MWE provides \lboxed and \rboxed which are truncated \fboxes. Technically, this is identical to \fbox only with the right/left \vrule removed (the definition of \fbox is taken from latex.ltx). It also provides \llboxed and \rrboxed which are array-style boxes with the required side stripped of its vertical rule.

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\lboxed}[1]{\begin{array}{|l}\hline#1\\\hline\end{array}}
\newcommand{\rboxed}[1]{\begin{array}{r|}\hline#1\\\hline\end{array}}
\makeatletter
\newcommand{\llboxed}[1]{{%
  \let\@frameb@x\l@frameb@x\fbox{#1}%
}}
\newcommand{\rrboxed}[1]{{%
  \let\@frameb@x\r@frameb@x\fbox{#1}%
}}

\def\l@frameb@x#1{%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep
  \advance\@tempdima\dp\@tempboxa
  \hbox{%
    \lower\@tempdima\hbox{%
      \vbox{%
        \hrule\@height\fboxrule
        \hbox{%
          \vrule\@width\fboxrule
          #1%
          \vbox{%
            \vskip\fboxsep
            \box\@tempboxa
            \vskip\fboxsep}%
          #1%
          %\vrule\@width\fboxrule% Right \vrule removed
                    }%
        \hrule\@height\fboxrule}%
                          }%
        }%
}
\def\r@frameb@x#1{%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep
  \advance\@tempdima\dp\@tempboxa
  \hbox{%
    \lower\@tempdima\hbox{%
      \vbox{%
        \hrule\@height\fboxrule
        \hbox{%
          %\vrule\@width\fboxrule% Left \vrule removed
          #1%
          \vbox{%
            \vskip\fboxsep
            \box\@tempboxa
            \vskip\fboxsep}%
          #1%
          \vrule\@width\fboxrule}%
        \hrule\@height\fboxrule}%
                          }%
        }%
}
\makeatother
\begin{document}
This is my equation $\boxed{q_1^{\ast}}=\dfrac{26-2\cdot 1 -4\cdot 2}{2\cdot 1}=\boxed{8}$

This is my equation $\rboxed{q_1^{\ast}}=\dfrac{26-2\cdot 1 -4\cdot 2}{2\cdot 1}=\lboxed{8}$

This is my equation $\rrboxed{$q_1^{\ast}$}=\dfrac{26-2\cdot 1 -4\cdot 2}{2\cdot 1}=\llboxed{$8$}$
\end{document}
Werner
  • 603,163
  • Any reason not to define \let\@frameb@x\l@frameb@x\fbox{$#1$} instead to ease the use of \rrboxed and \llboxed? I've tried it and the log doesn't seem to give any error. – Alfredo Hernández Feb 01 '16 at 00:05