10

Does anyone know how to produce a half-box symbol in LaTeX which comprises a bar over an entire expression and a vertical line on the right meeting in the corner, like the top and the right edge of a box?

I currently use \overline{abc}\vert as a compromise (say, abc is the text I wish to enclose) but clearly the bar and the vertical line do not meet each other in the top-right corner.

Thanks

user42427
  • 103
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Will this symbol only be used in math mode? – Herr K. Dec 09 '13 at 04:47
  • If you need it for annuities, look at http://tex.stackexchange.com/questions/140065/typesetting-annuity-and-life-insurance-symbols-in-context – egreg Dec 09 '13 at 08:59

3 Answers3

13

A TikZ approach.

Code

\documentclass{article}
\usepackage{tikz}

\newcommand\halfbox[1]{
  \tikz[baseline=(n.base)]{\node(n)[inner sep=1pt]{$#1$};
    \draw[line cap=round](n.north west)--(n.north east)--(n.south east);
  }
}

\begin{document}
$f(x)=\overline{abc}\vert$

$f(x)=\halfbox{abc}$
\end{document}

Output

enter image description here

Herr K.
  • 17,946
  • 4
  • 61
  • 118
12

The following takes most of the elements from the LaTeX kernel \framebox to construct a \halfbox:

enter image description here

\documentclass{article}

\makeatletter
\newcommand{\halfbox}[1]{%
  \setbox\@tempboxa\hbox{#1\kern\fboxsep}%
  \hbox{%
    \lower\@tempdima\hbox{%
      \vbox{%
        \hrule\@height\fboxrule
        \hbox{%
          \vbox{%
            \vskip\fboxsep
            \box\@tempboxa
            \vskip\dimexpr\fboxsep+\fboxrule\relax%
          }%
          \vrule\@width\fboxrule}%
        }%
      }%
  }}
\makeatother

\begin{document}

\fbox{abc}\ \halfbox{abc}

\end{document}

Since it uses the same construction as \framebox, lengths \fboxrule and \fboxsep can be adjusted in the same way.

Werner
  • 603,163
3

You probably want an actuarial symbol annuity. One of the solutions is the following macro, taken from ftp://ftp.mackichan.com/swandswp30/support/actuarial.tex,‎ with the usage {\bx argument}:

\documentclass{article}


\begin{document}

\newbox\tmp
\newdimen\height
\newdimen\dropdist
\def\BX#1{\setbox\tmp=\hbox{$\overline{\scriptstyle #1}$}
              \height=\ht\tmp
              \dropdist=\dp\tmp
              \advance\dropdist by .7pt
              \advance\height by \dp\tmp
              \box\tmp
              \lower \dropdist \hbox{\vrule height
              \height width .25pt\relax}
              \ifnum0=`{\else}\fi
}
\def\bx{\expandafter\BX\expandafter{\ifnum0=`}\fi}

\[
{\bx x+y+z\,}
\]
\end{document}

enter image description here

If it will not be used in such a context, some modifications are needed, in particular remowing \scriptstyle before an argument.

  • That's brilliant. It was indeed for typesetting an actuarial science document which I am helping out with. – user42427 Dec 09 '13 at 08:58
  • 6
    The rules have different widths. There are far better solutions around – egreg Dec 09 '13 at 09:00
  • @egreg Yes, these solutions look nicer. However, for some reason the author made such a box. With the suggested knowledge OP can seek for the best solution. And an argument only for fun: the hunting for two gold badges begun. ;-) – Przemysław Scherwentke Dec 11 '13 at 16:30