Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If I compile the following code, I get a table that is placed very oddly since LaTeX centers it around the double vertical line between the first and second column. My \hline also goes only to right after the first column. The text 'Position' also centers wrongly because of this. I tried to compile in different environments, but this doesn't seem to help.

The code:

\begin{table}
\begin{center}
\begin{tabular}{ r||cccccccc }
\hline
\multirow{2}{*}{Steps} & \multicolumn{8}{c}{Position}\\
\cline{2-8}
 & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$\\
\hline
\hline
$0$ & & & & $1$ & & & \\
$1$ & & & $|b|^{2}$ & & $|a|^{2}$ & &\\
$2$ & & $|a|^{2}|b|^{2}$ & & $|b|^{2}$ & & $|a|^{4}$ &\\
$3$ & $|a|^{4}|b|^{2}$ & & $\left(|b|^{4}-|a|^{2}|b|^{2}+|a|^{4}\right)|b|^{2}$ & & $|a|^{2}|b|^{2}\left(1+3|b|^{2}\right)$ & & $|a|^{6}$\\
$4$ & & \ldots & & \ldots & & \ldots &
\end{tabular}
\end{center}
\end{table}

Anybody any idea?

share|improve this question

2 Answers 2

Would this be what you seek? It seems that you got errors in two places

cline[2-9] and a missing & following it at the end.

enter image description here

Code

\documentclass[12pt]{article}
\usepackage{array}
\usepackage{threeparttable,multirow}


\begin{document}

\begin{table}[hbtp]
\begin{center}
\begin{tabular}{ r||cccccccc}\hline
\multirow{2}{*}{Steps} & \multicolumn{8}{c}{Position}\\  \cline{2-9}
  & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$ & \\
\hline \hline
 $0$ & & & & $1$ & & & \\
 $1$ & & & $|b|^{2}$ & & $|a|^{2}$ & &\\
 $2$ & & $|a|^{2}|b|^{2}$ & & $|b|^{2}$ & & $|a|^{4}$ &\\
 $3$ & $|a|^{4}|b|^{2}$ & & $\left(|b|^{4}-|a|^{2}|b|^{2}+|a|^{4}\right)|b|^{2}$ & & $|a|^{2}|b|^{2}\left(1+3|b|^{2}\right)$ & & $|a|^{6}$\\
 $4$ & & \ldots & & \ldots & & \ldots &
\end{tabular}
\end{center}
\end{table}

\end{document}
share|improve this answer
    
Wow. I did not know I would get an answer this fast. Thanks. This was indeed the error. I solved it (with some help) by leaving out one c in the beginning and setting \multicolumn{7}{c}{Position}. So essentially this is the same. Thanks again for the effort! –  Tim Apr 27 at 10:39

Replacing the two consecutive \hline with an \hhline both solves the problem and gives a better looking aspect to your table. I suggest also to improve it using the cellspace package for a better vertical spacing, an array environment rather than tabular (simpler code), having the maths in medsize (intermediate between \textstyle and \displaystyle) defined in the nccmath package and replacing the cline with boldface headers.

\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[showframe, noheadfoot, nomarginpar]{geometry} 
\usepackage{amsmath} 
\usepackage{nccmath} 
\usepackage{array}
\usepackage{multirow} 
\usepackage{hhline} 
\usepackage[math]{cellspace} 
\setlength\cellspacetoplimit{6pt}
\setlength\cellspacebottomlimit{6pt}

\begin{document}

Text text text text text text text text text. 
\begin{table}[!h]
\[ \begin{medsize}\begin{array}{ Sr||*{8}{ >{$}Sc<{$}}}
\hhline{-||*{8}{-}}
\multirow{2}{*}{\normalsize\bfseries Steps} &\multicolumn{8}{Sc}{\textbf{\normalsize Position}}\\
 & -3 & -2 & -1 & 0 & 1 & 2 & 3\\
\hhline{=::*{8}{=}}
0 & & & & 1 & & & \\
1 & & & |b|^{2} & & |a|^{2} & &\\
2 & & |a|^{2}|b|^{2} & & |b|^{2} & & |a|^{4} &\\
3 & |a|^{4}|b|^{2} & & \left(|b|^{4}-|a|^{2}|b|^{2}+|a|^{4}\right)|b|^{2} & & |a|^{2}|b|^{2}\left(1+3|b|^{2}\right) & & |a|^{6}\\
4 & & \ldots & & \ldots & & \ldots &
\end{array}\end{medsize} \]
\caption{A table}
\end{table}

Text text text text text text text text text.

\end{document} 

enter image description here

If you want to stick to your initial layout, it is enough to play with (at least one) \hhline. I don't why \hhline makes all work… Here are two ways:

     \begin{table}
    \begin{center}
    \begin{tabular}{ r||*{8}{c}}
    \hhline{-||*{8}{-}}
    \multirow{2}{*}{Steps} & \multicolumn{8}{c}{Position}\\
    \cline{2-8}
     & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$\\
            \hhline{=::*{8}{=}}
    $0$ & & & & $1$ & & & \\
    $1$ & & & $|b|^{2}$ & & $|a|^{2}$ & &\\
    $2$ & & $|a|^{2}|b|^{2}$ & & $|b|^{2}$ & & $|a|^{4}$ &\\
    $3$ & $|a|^{4}|b|^{2}$ & & $\left(|b|^{4}-|a|^{2}|b|^{2}+|a|^{4}\right)|b|^{2}$ & & $|a|^{2}|b|^{2}\left(1+3|b|^{2}\right)$ & & $|a|^{6}$\\
    $4$ & & \ldots & & \ldots & & \ldots &
    \end{tabular}
    \end{center}
    \end{table}

    \begin{center}
    \begin{tabular}{ r||*{8}{c}}
    \hhline{-|*{8}{-}}
    \multirow{2}{*}{Steps} & \multicolumn{8}{c}{Position}\\
    \cline{2-8}
     & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$\\
     \hhline{=*{8}{=}}
            %\hhline{=||*{8}{=}}
    $0$ & & & & $1$ & & & \\
    $1$ & & & $|b|^{2}$ & & $|a|^{2}$ & &\\
    $2$ & & $|a|^{2}|b|^{2}$ & & $|b|^{2}$ & & $|a|^{4}$ &\\
    $3$ & $|a|^{4}|b|^{2}$ & & $\left(|b|^{4}-|a|^{2}|b|^{2}+|a|^{4}\right)|b|^{2}$ & & $|a|^{2}|b|^{2}\left(1+3|b|^{2}\right)$ & & $|a|^{6}$\\
    $4$ & & \ldots & & \ldots & & \ldots &
    \end{tabular}
    \end{center}

and the results:

enter image description here

share|improve this answer
    
Despite the fact that this was not exactly what I was looking for, you taught me a lot of new things with this example. It looks great. I might use it. Thanks for the clear explanation! –  Tim Apr 27 at 10:45
    
@Tim: I added an example just using \hhline, not changing your code otherwise. I hope this will be closer to what you had in mind. –  Bernard Apr 27 at 12:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.