8

I'm trying to make a table, but some vertical lines are missing. Could someone help me to see the mistake?

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{dsfont}
\parindent0em
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{multirow}


\begin{document}

\begin{tabular}{c|c|c|c|c|c|c|c|} 
\cline{2-8} & \multicolumn{1}{c|}{Generacion} & Nombre & Simbolo & Masa(eV) & Espin & Carga($e$) & Color \\ \cline{1-8} 

\multicolumn{1}{ |c| }{\multirow{3}{*}{Quarks} } & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
& \multicolumn{1}{ |c| }{} & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
\multicolumn{1}{ |c| }{}& \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\  
&\multicolumn{1}{ |c| }{} & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8} 
\multicolumn{1}{ |c| }{} & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\  
&\multicolumn{1}{ |c| }{} & UP & 2 & 0 & 1 &5& 5\\ \cline{1-8} 
\cline{1-8} 

\multicolumn{1}{ |c| }{\multirow{3}{*}{Leptones} } & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
\multicolumn{1}{ |c| }{} & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\  
& & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8} 
\multicolumn{1}{ |c| }{} & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\  
& & UP & 2 & 0 & 1 &5& 5\\ \cline{1-8} 
\cline{1-8} 


\multicolumn{2}{|c|}{\multirow{5}{*}{Bosones}} & UP & 2 & 0 & 1 &5& 5\\ 
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\          
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ 
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}
\cline{1-8} 

\end{tabular}

\end{document}

This is how the table looks

Thanks

5 Answers 5

9

An important issue not mentioned in your posting is that the table is too wide to fit inside the text block. This may be remedied by (i) placing the units in two of the header cells in a separate row and (ii) reducing the value of \tabcolsep, the parameter that governs the amount of intercolumn whitespace, by a third (from 6pt to 4pt.

The table code is, I hope you don't mind the criticism, rather cluttered. It may be simplified considerably by (a) setting the structure via

\begin{tabular}{|*{8}{c|}}

and (b) getting rid of the multitude of \multicolumn{1}{ |c| }{} directives. Do also replace all \cline{1-8} directives with \hline and drop the three redundant \cline instructions.

enter image description here

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{dsfont}
\parindent0em
\usepackage{multirow,array}
\begin{document}

\setlength\tabcolsep{4pt} % default value: 6pt

\begin{tabular}{|*{8}{c|}} 
\cline{2-8} 
\multicolumn{1}{c|}{}& Generacion & Nombre & Simbolo & Masa & Espin & Carga  & Color \\ 
\multicolumn{1}{c|}{}& & & & (eV) & ($e$) &  & \\
\hline 
\multirow{3}{*}{Quarks} & \multirow{2}{*}{1a} 
                       & UP & 2 & 0 & 1 &5& 5\\
&                      & UP & 2 & 0 & 1 &5& 5\\ 
\cline{2-8}
& \multirow{2}{*}{2a}  & UP & 2 & 0 & 1 &5& 5\\  
&                      & UP & 2 & 0 & 1 &5& 5\\ 
\cline{2-8} 
& \multirow{2}{*}{3a}  & UP & 2 & 0 & 1 &5& 5\\  
&                      & UP & 2 & 0 & 1 &5& 5\\ 
\hline 
\multirow{3}{*}{Leptones} & \multirow{2}{*}{1a} 
                       & UP & 2 & 0 & 1 &5& 5\\
&                      & UP & 2 & 0 & 1 &5& 5\\ 
\cline{2-8}
& \multirow{2}{*}{2a}  & UP & 2 & 0 & 1 &5& 5\\  
&                      & UP & 2 & 0 & 1 &5& 5\\ 
\cline{2-8} 
& \multirow{2}{*}{3a}  & UP & 2 & 0 & 1 &5& 5\\  
&                      & UP & 2 & 0 & 1 &5& 5\\ 
\hline  
\multicolumn{2}{|c|}{\multirow{5}{*}{Bosones}} 
                       & UP & 2 & 0 & 1 &5& 5\\ 
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\          
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ 
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ 
\cline{3-8}
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ 
\hline 

\end{tabular}
\end{document}

Optional: All these vertical and horizontal lines do not contribute to the table's legibility and intelligibility; I would assume that these two criteria are important to your work. Dropping all vertical lines, replacing the \cline instructions with a bit of (vertical) whitespace, and using the rule-drawing macros (\toprule, \midrule, and \bottomrule) of the booktabs package gives you the following look -- I hope you will agree that it looks at least as good as the table above:

enter image description here

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{dsfont}
\parindent0em
\usepackage{multirow,array,booktabs}
\begin{document}
\setlength\tabcolsep{4pt}

\begin{tabular}{@{}l*{7}{c}@{}} 
\toprule 
& Generacion & Nombre & Simbolo & Masa & Espin & Carga  & Color \\ 
& & & & (eV) & ($e$) &  & \\
\midrule 
\multirow{3}{*}{Quarks}  & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ \addlinespace
& \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\  
& & UP & 2 & 0 & 1 &5& 5\\ \addlinespace 
& \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\  
&{} & UP & 2 & 0 & 1 &5& 5\\ 
\midrule 
\multirow{3}{*}{Leptones}  & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ 
\addlinespace
& \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\  
& & UP & 2 & 0 & 1 &5& 5\\ 
\addlinespace 
 & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\  
& & UP & 2 & 0 & 1 &5& 5\\ 
\midrule  
\multicolumn{2}{c}{\multirow{5}{*}{Bosones}} & UP & 2 & 0 & 1 &5& 5\\ 
&  & UP & 2 & 0 & 1 &5& 5\\          
&  & UP & 2 & 0 & 1 &5& 5\\ 
&  & UP & 2 & 0 & 1 &5& 5\\ 
\addlinespace
&  & UP & 2 & 0 & 1 &5& 5\\ 
\bottomrule 
\end{tabular}

\end{document}
5

Use

\begin{tabular}{|c|c|c|c|c|c|c|c|} 

if you really want vertical lines - it is not recommended - and get rid of the unneeded \multicolumn{1}{|c|}{}s.

lines

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{parskip}

\begin{document}

\begin{tabular}{|c|c|c|c|c|c|c|c|}
  \cline{2-8} \multicolumn{1}{c}{}& \multicolumn{1}{|c|}{Generacion} & Nombre & Simbolo & Masa(eV) & Espin & Carga($e$) & Color \\ \cline{1-8}

\multirow{3}{*}{Quarks}  & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
&  & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
& \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
 & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ \cline{1-8}

\multirow{3}{*}{Leptones}  & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
 & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
 & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\
& & UP & 2 & 0 & 1 &5& 5\\ \cline{1-8}


\multicolumn{2}{|c|}{\multirow{5}{*}{Bosones}} & UP & 2 & 0 & 1 &5& 5\\
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}

\end{tabular}

\end{document}

I would, however, urge you to reconsider your presentation. I highly recommend taking a look at booktabs documentation on creating professional quality tables.

A quick makeover:

made-over table

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow,booktabs}
\usepackage{parskip}

\begin{document}

  \begin{tabular}{*{8}{c}}
  \toprule & Generacion & Nombre & Simbolo & Masa(eV) & Espin & Carga($e$) & Color \\\midrule

  \multirow{3}{*}{Quarks}  & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
  &  & UP & 2 & 0 & 1 &5& 5\\ \cmidrule{2-8}
  & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\ \cmidrule{2-8}
  & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\
  \midrule

  \multirow{3}{*}{Leptones}  & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\ \cmidrule{2-8}
  & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\ \cmidrule{2-8}
  & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\
  \midrule

  \multicolumn{2}{c}{\multirow{5}{*}{Bosones}} & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\
  & & UP & 2 & 0 & 1 &5& 5\\ \cmidrule{3-8}
  & & UP & 2 & 0 & 1 &5& 5\\
  \bottomrule

\end{tabular}
3
  • 1
    In the version with the vertical rules, I'd also get rid of the redundant \cline{1-8} and \cline{3-8} directives (three in all) and replace the remaining \cline{1-8} statements with \hline.
    – Mico
    Commented Jul 11, 2015 at 1:27
  • @Mico Thanks. I meant to do that and must have forgotten to go back.
    – cfr
    Commented Jul 11, 2015 at 2:51
  • Thank you everyone for your advice. It was very helpful!
    – isk27
    Commented Jul 11, 2015 at 18:58
3

Here you are. The following code proposes two versions for this table.

– First, a table with horizontal and all vertical rules, slightly improved (cells in the first column are vertically centred).

– Then a solution without vertical rules, and much fewer horizontal rules, based on booktabs, resulting in a simpler code, and much better looking, in my opinion:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\parindent0em
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{multirow, makecell}
\usepackage{cellspace, booktabs}
\setlength\cellspacetoplimit{5pt}
%\setlength\cellspacebottomlimit{4pt}

\begin{document}

\begin{tabular}{|c|c|Sc|c|c|c|c|c|}
  \cline{2-8}
  \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{Generacion} & Nombre & Simbolo & Masa(eV) & Espin & Carga($e$) & Color \\ \cline{1-8}
  \multicolumn{1}{|c|}{\multirowcell{6}[-5pt]{Quarks}} & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                           & \multicolumn{1}{ c| }{} & UP & 2 & 0 & 1 & 5 & 5 \\ \cline{2-8}
  & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                           & \multicolumn{1}{c |}{} & UP & 2 & 0 & 1 & 5 & 5 \\ \cline{2-8}
  & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                           & \multicolumn{1}{c| }{} & UP & 2 & 0 & 1 & 5 & 5 \\ \cline{1-8}
  \cline{1-8}

  \multicolumn{1}{ |c| }{\multirow{6}{*}[-5pt]{Leptones} } & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                           & & UP & 2 & 0 & 1 & 5 & 5 \\ \cline{2-8}
   & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                           & & UP & 2 & 0 & 1 & 5 & 5 \\ \cline{2-8}
  & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                           & & UP & 2 & 0 & 1 & 5 & 5 \\ \cline{1-8}
  \cline{1-8}

  \multicolumn{2}{|c|}{\multirow{5}{*}[-5pt]{Bosones}} & UP & 2 & 0 & 1 &5& 5\\
  \multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\
  \multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\
  \multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}
  \multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}
  \cline{1-8}
\end{tabular}

\begin{tabular}{l*{7}{c}}
  \cmidrule[\heavyrulewidth]{2-8}
  \multicolumn{1}{c}{} & \multicolumn{1}{c}{Generacion} & Nombre & Simbolo & Masa(eV) & Espin & Carga($e$) & Color \\
  \cmidrule(lr){2-8}
  \multicolumn{1}{c}{\multirowcell{6}[-5pt]{Quarks}} & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \addlinespace
                                                      & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \addlinespace
                                                      & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \cmidrule(lr){2-8}

  %
  \multicolumn{1}{c}{\multirow{6}{*}[-5pt]{Leptones}} & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \addlinespace
                                                      & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \addlinespace
                                                      & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \cmidrule(lr){2-8}
  %
  \multicolumn{2}{c}{\multirow{5}{*}[-5pt]{Bosones}} & UP & 2 & 0 & 1 &5& 5\\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \cmidrule(lr){3-8}
                                                      & & UP & 2 & 0 & 1 & 5 & 5 \\
  \cmidrule[\heavyrulewidth]{3-8}
\end{tabular}

\end{document} 

enter image description here

enter image description here

8
  • 1
    I find this a bit confusing. You start by saying you are proposing a solution with features X and Y but then immediately provide a solution which has neither of them. Then you provide a second solution which does, indeed, have both X and Y. Wondered if you might want to include some more sign-posting.
    – cfr
    Commented Jul 11, 2015 at 2:53
  • @cfr: ??? For me, I first solved the problem as posed by the O.P., then suggested (like all of us) a better solution based on booktabs. Anyway, I added some explanations to make that clearer. Is it less confusing now?
    – Bernard
    Commented Jul 11, 2015 at 9:31
  • Yes, I find that much clearer. (+1) but I think you mean 'fewer horizontal rules' ;).
    – cfr
    Commented Jul 11, 2015 at 12:21
  • 1
    @cfr: Apparently I forgot some subtleties of English grammar…;o( Corrected, thank you.
    – Bernard
    Commented Jul 11, 2015 at 12:35
  • It is a pet peeve. However, it will probably count as correct soon because the BBC now says things like 'less people' but they probably don't mean an equal number of smaller or lighter people.
    – cfr
    Commented Jul 11, 2015 at 12:41
1

you need \multicolumn{2}{|c|}{} in first column

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{dsfont}
\parindent0em
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{multirow}


\begin{document}

\begin{tabular}{c|c|c|c|c|c|c|c|} 
\cline{2-8} & \multicolumn{1}{c|}{Generacion} & Nombre & Simbolo & Masa(eV) & Espin & Carga($e$) & Color \\ \cline{1-8} 

\multicolumn{1}{ |c| }{\multirow{3}{*}{Quarks} } & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
\multicolumn{1}{ |c| }{}& \multicolumn{1}{ |c| }{} & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
\multicolumn{1}{ |c| }{}& \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\  
\multicolumn{1}{ |c| }{}&\multicolumn{1}{ |c| }{} & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8} 
\multicolumn{1}{ |c| }{} & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\  
\multicolumn{1}{ |c| }{}&\multicolumn{1}{ |c| }{} & UP & 2 & 0 & 1 &5& 5\\ \cline{1-8} 
\cline{1-8} 

\multicolumn{1}{ |c| }{\multirow{3}{*}{Leptones} } & \multirow{2}{*}{1a} & UP & 2 & 0 & 1 &5& 5\\
\multicolumn{1}{ |c| }{}& & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8}
\multicolumn{1}{ |c| }{} & \multirow{2}{*}{2a} & UP & 2 & 0 & 1 &5& 5\\  
\multicolumn{1}{ |c| }{}& & UP & 2 & 0 & 1 &5& 5\\ \cline{2-8} 
\multicolumn{1}{ |c| }{} & \multirow{2}{*}{3a} & UP & 2 & 0 & 1 &5& 5\\  
\multicolumn{1}{ |c| }{}& & UP & 2 & 0 & 1 &5& 5\\ \cline{1-8} 
\cline{1-8} 


\multicolumn{2}{|c|}{\multirow{5}{*}{Bosones}} & UP & 2 & 0 & 1 &5& 5\\ 
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\          
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ 
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}
\multicolumn{2}{|c|}{} & UP & 2 & 0 & 1 &5& 5\\ \cline{3-8}
\cline{1-8} 

\end{tabular}

\end{document}

enter image description here

0

& were missing

I had the same problem, when I added another column to my multirow multicolumn table. The new column was missing the vertical line in some rows.

enter image description here

I realized that in creating the table I forgot to add & in all "placeholder rows". It resolved the issue.

enter image description here

Usually build would complain about such a missing & and stop building, but these tables seem more complex and error resistant.

Summary

These multirow multicolumn get hard to overlook and a "placeholder row" in one column, may be a regular row in another.

2
  • I believe forgetting & would result in missing | on the right side, but not on the left, which OP seems to have. (And omitting & won't cause an error.)
    – Teepeemm
    Commented Dec 9, 2023 at 21:37
  • Referring to the first statement and the headline, I found it a matching response, as this happened to me but to the right side and others might end up here for the same reason. My experience is, that omitting an & leads to latex stopping to build
    – spaceKelan
    Commented Dec 10, 2023 at 3:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .