1

I want to write this enter image description here. I used $\bar{A$\cup$B}$ but something wrong. Can someone help me?

OPended
  • 21
  • 5
    Welcome to TeX.SX! This is a single formula: $\overline{A\cup B}$. If it's part of a bigger formula, start the whole formula with $ and end it with $, with none in between. – egreg Oct 30 '16 at 13:39

1 Answers1

1

Your "formula", viz.,

$\bar{A$\cup$B}$

contains (at least) three syntax errors:

  • the first subformula, $\bar{A$, contains an opening curly brace but no closing curly brace;

  • the middle subformula, \cup, is encountered outside of math-mode; and

  • the third subformula, $B}$, contains a closing curly brace but no corresponding opening curly brace.


The \bar macro places a short horizontal bar across its argument. Hence, $\bar{A\cup B}$ results in a single, short bar across the entire formula. This isn't likely to be what you want. $\bar{A}\cup\bar{B}$ will produce two short horizontal bars -- again, not what you want.

If a single horizontal bar across A, \cup and B is required, you should be writing

$\overline{A\cup B}$

Some people may find that the line drawn by \overline can look too long and, as a result, too "heavy". If you are in this camp, you may find the \widebar macro useful. The code for the \widebar macro, used in the example code below, is taken straight from an earlier posting by Hendrik Vogt.

enter image description here

\documentclass{article}
\usepackage{amsmath}  % required for the following code

%%% The following code was created by Hendrik Vogt; see 
%%% https://tex.stackexchange.com/a/60253/5001 for details.
%%% Note that the 'amsmath' package is required.
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
  \setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
  \setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
  \ifdim\ht0=\ht2 #3\else #2\fi
  }
%The bar will be moved to the right by a half of 
%\macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then 
%no negative kern may follow the bar; an additional {} 
%makes sure that the superscript is high enough in 
%this case:
\newcommand*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
  \begingroup
  \def\mathaccent##1##2{%
%Enable nesting of accents:
    \let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the 
%first character instead (see below):
    \if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
    \setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
    \setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
    \dimen@\wd\tw@
    \advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
    \divide\dimen@ 3
    \@tempdima\wd\tw@
    \advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
    \divide\@tempdima 10
    \advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
    \ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
    \rel@kern{0.6}\kern-\dimen@
    \if#31
      \overline{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
      \advance\dimen@0.4\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it 
%is >0 or if a superscript follows:
      \let\final@kern#2%
      \ifdim\dimen@<\z@ \let\final@kern1\fi
      \if\final@kern1 \kern-\dimen@\fi
    \else
      \overline{\rel@kern{-0.6}\kern\dimen@#1}%
    \fi
  }%
  \macc@depth\@ne
  \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
  \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
  \macc@set@skewchar\relax
  \let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and 
%calls \mathaccent:
  \if#31
    \macc@nested@a\relax111{#1}%
  \else
%If the argument consists of more than one symbol, 
%and if the first token is a letter, use that letter 
%for the computations:
    \def\gobble@till@marker##1\endmarker{}%
    \futurelet\first@char\gobble@till@marker#1\endmarker
    \ifcat\noexpand\first@char A\else
      \def\first@char{}%
    \fi
    \macc@nested@a\relax111{\first@char}%
  \fi
  \endgroup
}
\makeatother
%%% End of Hendrik Vogt's code

\begin{document} 
%$\bar{A$\cup$B}$ %% This throws at least 3 syntax errors

$\bar{A\cup B}$      % much too short

$\bar{A}\cup\bar{B}$ % two separate short bars

$\overline{A\cup B}$ % looks rather "heavy"

$\widebar{A\cup B}$  % better-looking than \overline...
\end{document}
Mico
  • 506,678