I'm trying to write an expression in math mode similar to this formula:
My LaTeX expression looks like this:
\min \| \begin{array}{c} ... \end{array} \|
but it happens that the double lines are short:
How can I extend the double vertical bar?
delimitersmath-mode
I'm trying to write an expression in math mode similar to this formula:
My LaTeX expression looks like this:
\min \| \begin{array}{c} ... \end{array} \|
but it happens that the double lines are short:
How can I extend the double vertical bar?
This double bar should be treated as a binary relation, so it will be distinguishable from other usages, such as a norm.
The simplest way to cope with the problem is to use mathtools
facilities:
\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiterX{\infdivx}[2]{(}{)}{%
#1\;\delimsize\|\;#2%
}
\newcommand{\infdiv}{D\infdivx}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\begin{document}
\begin{gather}
D\left(P \middle\| Q\right) \rlap{\quad\itshape WRONG!} \\
% normal size
\infdiv{P}{Q} \\
% fixed size delimiters
\infdiv[\bigg]{\frac{\norm{P}}{2}}{Q} \\
% extensible delimiters
\infdiv*{\frac{\norm{P}}{2}}{Q}
\end{gather}
\end{document}
Note that number 1 is wrong in two respects: there is an unwanted space between the "D" and the left parenthesis; the two bars are too near the symbols, making for ambiguity.
Although I do not fully understand the macro \widebar
defined in the answer you linked to, I have managed to modify it to work for other accents (including stacked accents).
Here is the code:
\documentclass{article}
\usepackage{amsmath}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This code is a slight modification of Hendrik Vogt's \widebar %%
%% See: https://tex.stackexchange.com/questions/16337 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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*\wideaccent[2]{\@ifnextchar^{{\wide@accent{#1}{#2}{0}}}{\wide@accent{#1}{#2}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@accent[3]{\if@single{#2}{\wide@accent@{#1}{#2}{#3}{1}}{\wide@accent@{#1}{#2}{#3}{2}}}
\newcommand*\wide@accent@[4]{%
\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#42 \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#41
#1{\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#3%
\ifdim\dimen@<\z@ \let\final@kern1\fi
\if\final@kern1 \kern-\dimen@\fi
\else
#1{\rel@kern{-0.6}\kern\dimen@#2}%
\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#41
\macc@nested@a\relax111{#2}%
\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#2\endmarker
\ifcat\noexpand\first@char A\else
\def\first@char{}%
\fi
\macc@nested@a\relax111{\first@char}%
\fi
\endgroup
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\doubleoverline[1]{\overline{\overline{#1}}}
\newcommand\widebar{\wideaccent\overline}
\newcommand\widebarbar{\wideaccent\doubleoverline}
\begin{document}
\begin{tabular}{cc}
$\widebar{A \cup B}$
&
$\widebarbar{A \cup B}$
\\
\verb$\widebar{A \cup B}$
&
\verb$\widebarbar{A \cup B}$
\end{tabular}
\end{document}
Note that this also works for other combinations of accents:
\newcommand\hatoverline[1]{\widehat{\overline{#1}}}
\newcommand\widehatbar{\wideaccent\hatoverline}
\[
\widehat{\widebar{A}} \neq \widehatbar{A}
\]
Best Answer
Use the
\left ... \right
construction. See page 60 and table 3.8 of the Not so short intro. to LaTeX for further details.