0

How can I write an equation having the following term in LaTeX: enter image description here

The hard part for me is to align the W in the right hand side.

  • ?The W should be aligned in which way, exactly? – Bernard Jun 22 '18 at 21:06
  • @Bernard It should be on the same baseline as -\delta^*. – Heiko Oberdiek Jun 22 '18 at 21:23
2

You can have both a friendly syntax and varying size for inline and displayed formulas.

\documentclass{article}
\usepackage{amsmath,mleftright}

\makeatletter
\newcommand{\support}[1]{\aslv@support#1\@nil}
\def\aslv@support#1\\#2|#3\@nil{%
  \mleft(
  \genfrac..{0pt}{}{#1}{#2}
  \mskip\aslv@supportskip
  \middle|
  \mskip\aslv@supportskip
  #3
  \mright)
}
\newmuskip\aslv@supportskip
\aslv@supportskip=4mu % <--- adjust to suit
\makeatother

\begin{document}

We have the formula in line $\delta^+\support{1+d^Tr \\ V^Td+b(x) | W}$
or displayed
\[
\delta^+\support{1+d^Tr \\ V^Td+b(x) | W}
\]

\end{document}

enter image description here

  • 1
    A quite elegant code! – Bernard Jun 23 '18 at 8:35
3

There are a number of ways to achieve this. I list two below, the first using a pmatrix (from amsmath) and the other using regular \left/\right extensible parentheses (you can also use \mleft/\mright from mleftright):

enter image description here

\documentclass{article}

\usepackage{amsmath,mleftright}

\begin{document}

% Uses amsmath
\[
  a \begin{pmatrix}
    \begin{array}{@{} c | @{\hspace{\arraycolsep}}}
      b \\
      c
    \end{array}
    d
  \end{pmatrix}
\]

% Uses mleftright, but can also just use \left/\right instead of \mleft/\mright
\[
  a \mleft(
    \begin{array}{@{} c @{}}
      b \\
      c
    \end{array}
    \middle\vert
    d
  \mright)
\]

\end{document}

Both include an array for the split of b and c vertically centred with respect to a and d. The one uses \middle\vert to set the vertical rule, while the other uses the array vertical rule. You can intermix these.

  • 1
    Variation: Instead of \begin{array}{@{}c@{}}..\end{array}, package amsmath provides \begin{matrix}...\end{matrix}. – Heiko Oberdiek Jun 22 '18 at 21:24
3

Two other variants, with delarray or blkarray and \multirowcell from makecell:

\documentclass{article}

\usepackage{amsmath}
\usepackage{blkarray, delarray, multirow, makecell}

\begin{document}

\[
  -\delta^{*}\! \begin{array}({@{}c|c@{}})
1 + d^{\top}\tau & \multirowcell{2}{W} \\
V^{\top} d + b(x){}
\end{array}
\]

\[
   \begin{blockarray}{c(c|c)}
\BAmultirow{1em}{$ -\delta^{*} $} & 1 + d^{\top}\tau & \BAmultirow{1em}{$ W $} \\
& V^{\top} d + b(x){}
\end{blockarray}
\]

\end{document} 

enter image description here

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.