Graphics, Figures & Tableswhy the table I made has missing border lines

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
gcheer3
Posts: 41
Joined: Wed Jun 25, 2008 4:39 pm

why the table I made has missing border lines

Post by gcheer3 »

Hello,

I made a table. (not all the cells have data, I left the cell blank when there is no input). Thank you for any suggestions in advance.
My question is, 1, the table does not have the complete border line on the right. some part of the right border are missing. I don't know why.
2, The first title "Special First Group" is longer than the 2nd one, so the 2nd column of the table is wider than the 3rd column. Besides moving the word 'Group' into the 2nd line, is there a way to adjust the columns to make each column have equal width?

thank you very much.




\begin{document}
\begin{table}
\centering
\begin{tabular} {|l|c c c c|c c c c |c c c l|}
\hline
&\multicolumn{4}{c|}{Special First Group} &\multicolumn{4}{c|}{First Group} &\multicolumn{4}{c}{ Second Group}\\
& & & & & & & & &\multicolumn{4}{c} { with different n}\\
\hline
& $z_1$ & $z_2$ & $z_3$ & $z_4$& $z_1$ & $z_2$ & $z_3$ & $z_4$& $z_1$ & $z_2$ & $z_3$ & $z_4$ \\
\hline
all in one &0&0&0&0&0 &0 &1 &1 &1 & 1&1 &1\\[-1ex]
all in three&1&1&1&1& 5& 5& 5&\\
\hline
& 1 & 0 & 0 & 0 & 7& 7&7 &7 &7 & 3& 3&\\ [-1ex]
3 in one &0&1&0&0 &9 &9 1&5 &0 & 4&4 & 4&4\\[-1ex]
1 in three&0&0&1&0&0 &0 &1 & 5&0 &0 &0 &0\\[-1ex]
&0&0&0&1& & & & & & & &\\
\hline
&0&1&1&1& & 1&1 &1 & 1& 1& 1&1\\[-1ex]
1 in two &1&0&1&1& &3 & 3&3 &3 & 3& 0&\\[-1ex]
3 in three &1&1&0&1& & & & & 1&1 & &\\[-1ex]
&1&1&1&0& & & & &1 & 1& 1&\\
\hline

\end{tabular}
\end{table}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

why the table I made has missing border lines

Post by gmedina »

Hi,
gcheer3 wrote:...1, the table does not have the complete border line on the right. some part of the right border are missing. I don't know why...
Because your code is not complete. Try this (in the corresponding parts of your code):

Code: Select all

&\multicolumn{4}{c|}{Special First Group} &\multicolumn{4}{c|}{First Group} &\multicolumn{4}{c|}{ Second Group}\\
(I added a missing "|" character in the last \multicolumn) and

Code: Select all

all in three&1&1&1&1& 5& 5& 5&&&&&\\
(I added 4 missing "&" characters).
gcheer3 wrote:...2, The first title "Special First Group" is longer than the 2nd one, so the 2nd column of the table is wider than the 3rd column. Besides moving the word 'Group' into the 2nd line, is there a way to adjust the columns to make each column have equal width?..
One possibility would be to initially declare a four column table with column format , for example, lp{3cm}p{3cm}p{3cm} . Now, each of the last three columns will have equal width and will contain a tabular with four columns.

The following code illustrates this approach:

Code: Select all

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}

\newcommand\zhead{%
  \begin{tabular}{cccc}
    $z_1$ & $z_2$ & $z_3$ & $z_4$
  \end{tabular}}
\newcommand\mytabular[4]{%
  \begin{tabular}{*{3}{c@{\hspace{16.5pt}}}c}
    #1 & #2 & #3 & #4
\end{tabular}}

\begin{document}

\begin{table}[!ht]
  \centering
  \begin{tabular} {lp{3cm}p{3cm}p{3cm}}
    \toprule
    &\multicolumn{1}{c}{Special First Group} &\multicolumn{1}{c}{First Group} 
      &\multicolumn{1}{c}{ Second Group}\\
    \midrule
    & \zhead & \zhead & \zhead\\
    \midrule
    all in one & \mytabular{0}{0}{0}{0} & \mytabular{0}{0}{1}{1} & 
      \mytabular{1}{1}{1}{1}\\
    all in three & \mytabular{1}{1}{1}{1} & \mytabular{5}{5}{5}{} & \\
    \midrule
    & \mytabular{1}{0}{0}{0} & \mytabular{7}{7}{7}{7} & \mytabular{7}{3}{3}{}\\
    three in one & \mytabular{0}{1}{0}{0} & \mytabular{9}{\hspace*{-4pt}91}
      {\hspace*{-1pt}5}{0} & \mytabular{4}{4}{4}{4}\\
    1 in three & \mytabular{0}{0}{1}{0} & \mytabular{0}{0}{1}{5} & 
      \mytabular{0}{0}{0}{0} \\
    & \mytabular{0}{0}{0}{1} & & \\
    \midrule
    & \mytabular{0}{1}{1}{1} & \mytabular{\hphantom{0}}{1}{1}{1} & 
      \mytabular{1}{1}{1}{1} \\
    1 in two & \mytabular{1}{0}{1}{1} & \mytabular{\hphantom{0}}{3}{3}{3} & 
      \mytabular{3}{3}{0}{} \\
    3 in three & \mytabular{1}{1}{0}{1} & & \mytabular{1}{1}{}{} \\
    & \mytabular{1}{1}{1}{0} & & \mytabular{1}{1}{1}{} \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}
Remarks: 1) I took the liberty to modify your table; I used the booktabs package (in particular, no vertical lines were used (booktabs doesn't like vertical lines in tables and I don't either)). However, if you really need the vertical lines, you can modify my code to produce a table with the usual (in my opinion ugly, and (in some cases, as this one) not really necessary) vertical lines. My idea of suppressing the vertical lines is just a suggestion.
2) Feel free to adapt my example according to your needs.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
gcheer3
Posts: 41
Joined: Wed Jun 25, 2008 4:39 pm

Re: why the table I made has missing border lines

Post by gcheer3 »

Dear gmedina,

Thanks a lot for your help. I really appreciate you pointed out my mistake in the table. The border line shows up now:-)
I will read the code with booktabs package carefully. It does make the table looks better. Thanks for the suggestion!

gcheer3
Post Reply