Search code examples
latextabulartex

Specific table in Latex


I'm trying to get table like this:

enter image description here

but it's not looking such good, my code is

\begin{center}
\begin{tabular}{ c c c c }
    & & \textbf{Sferyczne} & \textbf{Kartezjańskie} \\ 
    $l=0$ & $y^{0}_{0}(\theta,\phi)=$ & $\sqrt{\frac{1}{4\pi}}$ & $\sqrt{\frac{1}{4\pi}}$ \\  
    $l=1$ & \begin{dcases} $y^{-1}_{1}(\theta,\phi)=$ \\ $y^{0}_{1}(\theta,\phi)=$ \\ $y^{1}_{1}(\theta,\phi)=$ \end{dcases} & \begin{tabular}{c} $\sqrt{\frac{3}{4\pi}}\cos\phi\sin\theta$ \\ g \\ g \end{tabular} & \begin{tabular}{c} $\sqrt{\frac{3}{4\pi}}x$ \end{tabular} \\
    cell10 & cell11 & cell12   
\end{tabular}
\end{center}

and there is how it looks:

enter image description here

Please help me to get the same table like on first picture.


Solution

  • Here is one way to achieve the output you desire:

    enter image description here

    \documentclass{article}
    
    \usepackage{xparse,eqparbox,amsmath}
    
    % https://tex.stackexchange.com/a/34412/5764
    \makeatletter
    \NewDocumentCommand{\eqmathbox}{o O{c} m}{%
      \IfValueTF{#1}
        {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
        {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
      \mathpalette\eqmathbox@{#3}
    }
    \makeatother
    
    \newcommand{\ts}{\quad}
    
    \begin{document}
    
    \[
      \renewcommand{\arraystretch}{2.5}
      \begin{array}{ r r }
              & \eqmakebox[c1]{} \ts 
                  \eqmakebox[c2][c]{\textbf{Spherical}} \ts 
                  \eqmakebox[c3][c]{\textbf{Cartesian}} \\
        l = 0 & \eqmathbox[c1][r]{y_0^0(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{1}{4 \pi}}} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{1}{4 \pi}},} \\
        l = 1 & \left\{\begin{array}{ @{} r @{} }
                \eqmathbox[c1][r]{y_1^{-1}(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{3}{4 \pi}} \sin \phi \sin \theta} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{3}{4 \pi}} x,} \\
                \eqmathbox[c1][r]{y_1^0(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{3}{4 \pi}} \cos \theta} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{3}{4 \pi}} z,} \\
                \eqmathbox[c1][r]{y_1^1(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{3}{4 \pi}} \cos \phi \sin \theta} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{3}{4 \pi}} y,}
              \end{array}\right.\kern-\nulldelimiterspace \\
        l = 2 & \left\{\begin{array}{ @{} r @{} }
                \eqmathbox[c1][r]{y_2^{-2}(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{15}{4 \pi}} \sin \phi \cos \phi \sin^2 \theta} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{15}{4 \pi}} x y,} \\
                \eqmathbox[c1][r]{y_2^{-1}(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{15}{4 \pi}} \sin \phi \sin \theta \cos \theta} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{15}{4 \pi}} y z,} \\
                \eqmathbox[c1][r]{y_2^0(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{5}{16 \pi}} (3 \cos^2 \theta - 1)} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{5}{16 \pi}} (3 z^2 - 1),} \\
                \eqmathbox[c1][r]{y_2^1(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{15}{4 \pi}} \cos \phi \sin \theta \cos \theta} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{15}{8 \pi}} x z,} \\
                \eqmathbox[c1][r]{y_2^2(\theta, \phi) =} \ts 
                  \eqmathbox[c2][l]{\sqrt{\dfrac{15}{16 \pi}} (\cos^2 \phi - \sin^2 \phi) \sin^2 \theta} \ts 
                  \eqmathbox[c3][l]{\sqrt{\dfrac{15}{32 \pi}} (x^2 - y^2).}
              \end{array}\right.\kern-\nulldelimiterspace \\
              & \eqmakebox[c1]{} \ts 
                  \eqmakebox[c2][c]{\textbf{Spherical}} \ts 
                  \eqmakebox[c3][c]{\textbf{Cartesian}}
      \end{array}
    \]
    
    \end{document}
    

    The approach uses boxes to fake a columnar alignment. The outer array contains only two right-aligned columns, the first for the l = ? construction, and the second for the rest. Each element within the second column is set inside a box (using either \eqmakebox or \eqmathbox) with a tag: \eq..box[<tag>][<align>]{<stuff>}. Each box with the same <tag> will have the same, maximum width and you can specify the individual box <align>ment.

    You can vary the number in \arraystretch to increase the vertical height of the entire construction. Also, \ts is inserted to represent a tabular separation, defaulting to a space of 1em (or \quad). You can change this to (say) \hspace{2cm} to insert a larger horizontal gap between the columns.