1

Consider the following tabularenter image description here with the code

 \documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{diagbox,amsmath,amssymb}

\begin{document}

\newcommand{\on}[1]{\ensuremath{\operatorname{#1}}}
    \begin{table}[h]
      \begin{center}
        \begin{tabular}{c|c|c}
          \diagbox{b}{d}&1&2\\ \hline
          1&$-(x_{a2}x_{c2}+\on{Re}(z_{n+a}\overline{z_{n+c}}))$&\\ 
          2&$2(x_{a1}x_{c2}+\on{Im}(z_{n+a}\overline{z_{n+c}}))$&$-(x_{a1}x_{c1}+\on{Re}(z_{n+a}\overline{z_{n+c}}))$\\
          3&$-2(x_{a4}x_{c2}-\on{Re}(z_{a}\overline{z_{n+c}}))$&$2(x_{a4}x_{c1}+\on{Im}(z_a\overline{z_{n+c}}))$\\
          4&$2(x_{a3}x_{c2}-\on{Im}(z_a\overline{z_{n+c}}))$&$-2(x_{a3}x_{c1}-\on{Re}(z_a\overline{z_{n+c}}))$
        \end{tabular}
      \end{center}
      \caption{Values of $\lambda_{abcd}$ for $d\in\{1,2\}$}
      \end{table}

\end{document}

Is it possible to align the cells to each other, so that the real and imaginary parts (as well as the signs in front of them) are aligned? Thanks in advance for any help.

3
  • 1
    please extend your code snippet to small but complete document which we can compile as it is.
    – Zarko
    Sep 15 '18 at 23:08
  • @Zarko Sure! I hope it is okay now. Sep 15 '18 at 23:21
  • Maybe you can group the 4 rows and create a new environment, like tabular.
    – manooooh
    Sep 15 '18 at 23:22
3

i suspect that you like to align real and imaginary parts of your math terms as follows:

enter image description here

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{diagbox,amsmath,amssymb}
\usepackage{array}
\newcommand{\on}[1]{\ensuremath{\operatorname{#1}}}

\begin{document}
\begin{table}[h]
\centering
\renewcommand\arraystretch{1.5}
\begin{tabular}{ c|>{$}r<{$}@{\,}>{$}l<{$} | >{$}r<{$}@{\,}>{$}l<{$} }
  \diagbox{b}{d}
    & \multicolumn{2}{c|}{1} & \multicolumn{2}{c}{2}    \\ \hline
  1 & -(x_{a2}x_{c2}    & +\on{Re}(z_{n+a}\overline{z_{n+c}}))     &&  \\
  2 & 2(x_{a1}x_{c2}    & +\on{Im}(z_{n+a}\overline{z_{n+c}}))
        & -(x_{a1}x_{c1}    & +\on{Re}(z_{n+a}\overline{z_{n+c}}))  \\
  3 & -2(x_{a4}x_{c2}   & -\on{Re}(z_{a}\overline{z_{n+c}}))
        & 2(x_{a4}x_{c1}    & +\on{Im}(z_a\overline{z_{n+c}}))      \\
  4 & 2(x_{a3}x_{c2}    &  -\on{Im}(z_a\overline{z_{n+c}}))
        & -2(x_{a3}x_{c1}   & -\on{Re}(z_a\overline{z_{n+c}}))
\end{tabular}
\caption{Values of $\lambda_{abcd}$ for $d\in\{1,2\}$}
\end{table}
\end{document}
6
  • Yes that's exactly what I wanted. Thank you for the quick response! But why is the 2 in the first row not centered? Sep 15 '18 at 23:33
  • 2
    @LukeMathwalker try to modify the second multicolumn to this: \multicolumn{2}{c}{2}.
    – manooooh
    Sep 15 '18 at 23:53
  • Thank you, that worked out for me. Is it better or more common to not center the second column? Sep 15 '18 at 23:59
  • @LukeMathwalker why do you say that? Because Zarko did it like that? I think he did not see that the number was misaligned, but it is not wrong to center the text; in fact, I think it's better because it helps to find the text quickly.
    – manooooh
    Sep 16 '18 at 0:05
  • @manooooh Well I was only wondering whether there is a reason for the alignment. Thank you anyway. Sep 16 '18 at 0:23

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.