# how to modify the following table

In the example below, you might see that I have a table:

I would like to change/introduce and understand the following:

1. How to change the column separator say to \Rightarrow. Normally one can do this by introducing @{$\Rightarrow$} when the columns are specified as {cc} etc. but in the "paragraph mode" as here, how is is done? In this case the implies sign (\Rightarrow) is shifted upwards.
2. How to make sure the numbering (2), (3) etc of table rows is aligned with the main numbering (the top (1) earlier?
3. How to introduce an align environment in column 2 (commented out in the example)?

\documentclass[leqno,10pt]{article}
\usepackage{soul}
\usepackage[margin=0.75in]{geometry}
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{mathtools}
\usepackage{enumitem,array}
\usepackage{relsize}
\usepackage{amsmath}
\usepackage{amsthm} %for proof
\newtheorem*{mythm}{Theorem}
\newtheorem*{mydef}{Definition}
\title{\ul{Conditional Expectations in Bivariate Probability Distribution}}
\date{}
\newenvironment{mydescription}{%
\renewcommand\descriptionlabel[1]{\hspace{\labelsep}\textbf{{##1}}}%
\begin{description}%
}{%
\end{description}%
}
\newenvironment{definition}[1][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}
\begin{document}

\newenvironment{Myitemize}{%
\renewcommand{\labelitemi}{{}}%
\begin{itemize}[nosep]}{\end{itemize}}

\maketitle

\newcommand{\myitem}{\stepcounter{enumi}\item[(\theenumi)]}%for enumerate with no. in brackets
\newcommand\litem[1]{\item{\bfseries {#1}}}

\thispagestyle{fancy}

\begin{definition}
If the random vector $(X,Y)$ has joint \textbf{pdf} $f(x,y)$ with conditional \textbf{pdf} $g_{2}(y|x)$, and if $Z=h(X,Y)$ is a (single-valued) function of (X,Y). Then the conditional expectation of the random variable $Z$, given $X=x$ is
$$E(Z|x)=\int_{-\infty}^{\infty}{h(x,y)g_{2}(y|x)dy} \label{eq:}$$
\end{definition}

\begin{mydescription}
\item[Special cases] (a,b,c are constants; ($X^{*}=X-E(X); Y^{*}=Y-E(Y)$)\\
\begin{tabular}[t]{>{\raggedright\arraybackslash}p{\dimexpr0.5\textwidth-2\tabcolsep-2\arrayrulewidth\relax}@{$\Rightarrow$}
>{\raggedright\arraybackslash}p{\dimexpr0.5\textwidth-2\tabcolsep-2\arrayrulewidth\relax}}
\begin{enumerate}[nosep,leftmargin=*,series=mylist,label=(\arabic{enumi}),start=2]
\item $Z=a+bX+cY$
\end{enumerate} &
\begin{Myitemize}
\item abc %\begin{align*}E(Z|x)&=E(a|x)+b.E(X|x)+c.E(Y|x)\\&=a+bx+c.E(Y|x) \end{align*}
\end{Myitemize}\\[-3ex]
\begin{enumerate}[nosep,resume*=mylist]
\item $Z=XY$
\end{enumerate} &
\begin{Myitemize}
\item def
\end{Myitemize}\\[-3ex]
\begin{enumerate}[nosep,resume*=mylist]
\item $Z=Y$
\end{enumerate}&
\begin{Myitemize}
\item 123
\end{Myitemize}\\[-3ex]
\begin{enumerate}[nosep,resume*=mylist]
\item $Z=(Y-\mu_{Y|X})^{2}$
\end{enumerate} &
\begin{Myitemize}
\item 456
\end{Myitemize}\\[-3ex]
\begin{enumerate}[nosep,resume*=mylist]
\item $Z=(Y-\mu_{Y})^{2}$
\end{enumerate} &
\begin{Myitemize}
\item 789
\end{Myitemize}\\[-3ex]
\end{tabular}
\end{mydescription}
\end{document}

• The last question is simple: \\[-3ex] means a line break, immediately followed by a negative vertical space of 3ex (ex is approximately the height of the letter x in the current font). – Bernard Aug 23 '14 at 14:42
• @Bernard: Thanks so much, finally I have grasped ex :-) – Abhimanyu Arora Aug 23 '14 at 14:46
• (4) It depends a bit on the details. The quick answer is 'yes' but the longer answer is that the results may or may not be what you want. Obviously non-paragraph column specs do just this. But you can also use other packages such as tabularx which allow you to use X to specify automatically-adjusted columns. For (1), what exactly is the problem with the @ method here? – cfr Aug 23 '14 at 15:44
• For point 1, you can use any separator you wish between any type of columns.But don't forget to write @{${}\Rightarrow{}$} (with both pairs of empty braces to ensure a correct spacing. – Bernard Aug 23 '14 at 20:24
• May be I'm completely mistaken, but I think you don't really need a tabular environment. It seems completely artificial. I'll propose another solution, based on amsmath in a moment. – Bernard Aug 23 '14 at 21:41

Here are two ways of doing things, first defining a \mycases environment in the definition style of amsthm, and two ways of having your equations aligned on the left margin — one defining a tabenum counter that's increased each time a\tabitem command is called (and it can be cross-referenced); the other simply uses theflalign environment, and thus the numbering of equations follows the general numbering of equations in the document. The following code lets you compare both ways — actually three if the second column has aligned equations. I added a macro for the conditional expected value, heavily borrowed from §3.6 of the mathtools doc, thathas better spacing and delimiters that automatically adjust to the size of the argument (with the * version):

\documentclass[leqno,10pt]{article}
\usepackage{soul}
\usepackage[margin=0.75in]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{mathtools}
\usepackage{array}
\usepackage{amsthm} %for proof
\newtheorem*{mythm}{Theorem}
\theoremstyle{definition}
\newtheorem*{mydef}{Definition}
\newtheorem*{mycases}{Special cases}
\title{\ul{Conditional Expectations in Bivariate Probability Distribution}}
\date{}
\author{}

\usepackage{tabularx}

\providecommand\given{}
\DeclarePairedDelimiterXPP\EV[1]{E}(){}{
\renewcommand\given{\nonscript\,\delimsize\vert\nonscript\,}
#1}

\begin{document}

\newenvironment{Myitemize}{%
\renewcommand{\labelitemi}{{}}%
\begin{itemize}[nosep]}{\end{itemize}}

\maketitle

\newcommand{\myitem}{\stepcounter{enumi}\item[(\theenumi)]}%for enumerate with no. in brackets
\newcommand\litem[1]{\item{\bfseries {#1}}}

\thispagestyle{fancy}

\begin{mydef}
If the random vector $(X,Y)$ has joint \textbf{pdf} $f(x,y)$ with conditional \textbf{pdf} $g_{2}(y|x)$, and if $Z=h(X,Y)$ is a (single-valued) function of (X,Y). Then the conditional expectation of the random variable $Z$, given $X=x$ is
$$\EV{Z \given x} = =\int_{-\infty}^{\infty}{h(x,y)g_{2}(y|x)dy} \label{eq:}$$
\end{mydef}

\begin{mycases}
(a,b,c are constants; ($X^{*}=X-E(X); Y^{*}=Y-E(Y)$)\\
%

\newcounter{tabenum}\setcounter{tabenum}{1}
\newcommand{\tabitem}{\refstepcounter{tabenum}(\thetabenum)}
\renewcommand\arraystretch{1.25}\noindent
\begin{tabularx}{\linewidth}{@{}l@{\enspace}>{\raggedright\arraybackslash $}X <{$}
!{{} $\Rightarrow${}} >{\raggedright\arraybackslash}X}
\tabitem & Z=a+bX+cY & \begin{aligned}[t]\EV{Z \given x}&=\EV{a \given x}+b.\EV{X \given x}+c.\EV{Y \given x}\\&=a+bx+c.\EV{Y \given x} \end{aligned}\\
\tabitem & Z=XY &def \\
\tabitem & Z=Y & 123 \\
\tabitem & Z=(Y-\mu_{Y|X})^{2} & 456 \\
\tabitem & Z=(Y-\mu_{Y})^{2} & 789
\end{tabularx}

\begin{flalign}\label{cas}
& Z=a+bX+cY & \Rightarrow\quad & \!\begin{aligned}[t]\EV{Z \given x}&=\EV{a \given x}+b.\EV{X \given x}+c.\EV{Y \given x} \\&= a+bx+c.\EV{Y \given x} \end{aligned} &\hphantom{Z=a+bX+cY\quad(2)} & \\
& Z=XY & \Rightarrow\quad & \text{def} \\
& Z = Y & \Rightarrow\quad & 123 \\
& Z=(Y-\mu_{Y|X})^{2} &\Rightarrow\quad & 456 \\
& Z=(Y-\mu_{Y})^{2} & \Rightarrow\quad & 789
\end{flalign}

\begin{flalign}\label{cas}
& Z=a+bX+cY & \Rightarrow\quad & \!\begin{aligned}[t]\EV{Z \given x}&=\mathrlap{\EV{a \given x}+b.\EV{X \given x}+c.\EV{Y \given x}}\\&=\mathrlap{a+bx+c.\EV{Y \given x}} \end{aligned} &\hphantom{Z=a+bX+cY\quad(2)} & \\
& Z=XY & \Rightarrow\quad & \text{def} \\
& Z = Y & \Rightarrow\quad & 123 \\
& Z=(Y-\mu_{Y|X})^{2} &\Rightarrow\quad & 456 \\
& Z=(Y-\mu_{Y})^{2} & \Rightarrow\quad & 789
\end{flalign}
\end{mycases}

\end{document}


• This is amazing. And suppose instead of "abc" I need to introduce an align environment as in the commented out part in the MWE, how should I do it please? – Abhimanyu Arora Aug 23 '14 at 22:46
• @AbhimanyuArora You should review the amsmath package documentation for see the different options for align single or block of equations. – Aradnix Aug 23 '14 at 23:46
• @AbhimanyuArora: That is easy with the aligned environment — we have 3 ways to do things now. See my updated answer. – Bernard Aug 24 '14 at 0:07
• Your code is broken up into two parts. additionally, please have a look at chat.stackexchange.com/transcript/message/17344334#17344334 – Johannes_B Aug 26 '14 at 7:25
• Sorry for this problem: I was aware that a line beginning with a % broke the code, and I hadn't re-read the display to check. @Johannes_B: Thanks for pointing me the problem. It's corrected now. – Bernard Aug 26 '14 at 7:42