1

I referenced the code from https://www.tablesgenerator.com/ and set the cell color. But I found the cell border disappeared in generated table.

enter image description here enter image description here

code:

% Please add the following required packages to your document preamble:
% \usepackage{multirow}
% \usepackage[table,xcdraw]{xcolor}
% If you use beamer only pass "xcolor=table" option, i.e. \documentclass[xcolor=table]{beamer}
\begin{table}[]
\begin{tabular}{|ccc|c|c|c|}
\hline
\rowcolor[HTML]{C0C0C0} 
\multicolumn{3}{|c|}{\cellcolor[HTML]{C0C0C0}Package}                                                             & \cellcolor[HTML]{C0C0C0}                       & \cellcolor[HTML]{C0C0C0}                                   & \cellcolor[HTML]{C0C0C0}                                  \\ \cline{1-3}
\rowcolor[HTML]{C0C0C0} 
\multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}QFP100} & \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}QFP64} & QFP48 & \multirow{-2}{*}{\cellcolor[HTML]{C0C0C0}Name} & \multirow{-2}{*}{\cellcolor[HTML]{C0C0C0}Digital Function} & \multirow{-2}{*}{\cellcolor[HTML]{C0C0C0}Analog Function} \\ \hline
\multicolumn{1}{|c|}{1}                              & \multicolumn{1}{c|}{1}                             & 1     & A                                              & A                                                          & -                                                         \\ \hline
\multicolumn{1}{|c|}{2}                              & \multicolumn{1}{c|}{2}                             & 2     & B                                              & B                                                          & -                                                         \\ \hline
\end{tabular}
\end{table}

I tried replaceing \cline{1-3} with hhline{---}, but the result was also problematic enter image description here

Another problem, when zoom to 80%, more borders are no longer displayed enter image description here

If the cell color is not set, there is no problem with the above enter image description here

Thanks

Youngman
  • 31
  • 2
  • Welcome to TeX.SX! Unrelated, but the code should be optimized: Change the column definitions from |ccc|c|c|c| to |c|c|c|c|c|c| and then remove all these \multicolumn{1}{...}{...} since they are not necessary. Finally, changing \\ \cline{1-3} to \\[-.4pt] \hhline{---~~~} should do the trick. – Jasper Habicht May 10 '23 at 09:22
  • This problem has been discussed already, apart from the question linked as duplicate also e.g. in https://tex.stackexchange.com/q/101249/47927 and https://tex.stackexchange.com/q/162814/47927 and https://tex.stackexchange.com/q/39761/47927 – Jasper Habicht May 10 '23 at 13:13

2 Answers2

1

Welcome to TeX.SE!!

I don't know your table generator (or any other, for that matter), but I think your table is easy to do with tabularray package. The code will be brief, simple and very legible (IMHO).

Something like this:

\documentclass{article}
\usepackage{lipsum}     % dummy text
\usepackage{tabularray} % clean tables
\usepackage{xcolor}     % colors

\definecolor{mygray}{HTML}{C0C0C0}

\begin{document} \lipsum[1] \begin{table}[ht]\centering \begin{tblr} {% format: colspec={cccccc}, % centered columns hlines,vlines, % horizontal and vertical lines cell{1}{1}={c=3}{}, % enlarege cell{1}{1} to 3 columns cell{1}{4-6}={r=2}{},% enlarge cells {1}{4}, {1}{5} and {1}{6} to 2 rows row{1,2}={bg=mygray},% fisrt 2 rows with gray background cells={font=\sffamily} }% content: Package & & & Name & Digital Function & Analog Function\ QFP100 & QFP64 & QFP48 & & &\ 1 & 1 & 1 & A & A & -\ 2 & 2 & 2 & B & B & - \end{tblr} \end{table}

\lipsum[2] \end{document}

enter image description here

Update: same example with longtblr suggested by the comments.

\documentclass{article}
\usepackage{lipsum}     % dummy text
\usepackage{tabularray} % clean tables
\usepackage{xcolor}     % colors

\definecolor{mygray}{HTML}{C0C0C0}

\begin{document} \lipsum[1-4] \begin{longtblr} [% longtable format: caption=Some title., ] {% format: colspec={cccccc}, hlines,vlines, % horizontal and vertical lines cell{1}{1}={c=3}{}, % enlarege cell{1}{1} to 3 columns cell{1}{4-6}={r=2}{},% enlarge cells {1}{4}, {1}{5} and {1}{6} to 2 rows row{1,2}={bg=mygray},% fisrt 2 rows with gray backgraound cells={font=\sffamily}, rowhead=2, }% content: Package & & & Name & Digital Function & Analog Function\ QFP100 & QFP64 & QFP48 & & &\ 1 & 1 & 1 & A & A & -\ 1 & 1 & 1 & A & A & -\ 1 & 1 & 1 & A & A & -\ 1 & 1 & 1 & A & A & -\ 1 & 1 & 1 & A & A & -\ 1 & 1 & 1 & A & A & -\ 2 & 2 & 2 & B & B & - \end{longtblr}

\lipsum[2] \end{document}

Juan Castaño
  • 28,426
  • @Youngman, tabularray package provides a longtblr environment, similar to longtable but with all the advantages of tabularray. In other order of things, why didn't you say that in your post? – Juan Castaño May 10 '23 at 07:58
  • Thanks, I'm trying longtblr. The earliest post, I only wanted to explain the problem with simple code, so I didn't mention longtable. – Youngman May 10 '23 at 08:07
1

Welcome to TeX.SX! The code can be simplified radically (which is not surprising, since table generators are known for the overly complicated code they produce):

  • Changing the column definitions from |ccc|c|c|c| to |c|c|c|c|c|c|. allows you to remove all instances of \multicolumn{1}{...}{...}.
  • If you use \rowcolor, there is no need to additionally add \cellcolor unless single cells should have another color, which is not the case here.
  • Finally, you can use \hhline, but you need to adjust the spacing a bit. So, changing \\ \cline{1-3} to \\[-.4pt] \hhline{---~~~} should do the trick.

Full MWE:

\documentclass{article}
\usepackage{colortbl, xcolor, multirow, hhline}

\begin{document}

\begin{tabular}{|c|c|c|c|c|c|} \hline \rowcolor[HTML]{C0C0C0} \multicolumn{3}{|c|}{Package} & & & \[-.4pt] \hhline{---~~~} \rowcolor[HTML]{C0C0C0} QFP100 & QFP64 & QFP48 & \multirow{-2}{}{Name} & \multirow{-2}{}{Digital Function} & \multirow{-2}{*}{Analog Function} \ \hline 1 & 1 & 1 & A & A & - \ \hline 2 & 2 & 2 & B & B & - \ \hline \end{tabular}

\end{document}

enter image description here