Graphics, Figures & Tables ⇒ Table with background color
Table with background color
Example in attachement.
If needed I can upload source code.
Example:
2 & \cellcolor[HTML]{3166FF}2. ORANGE & 2. GREEN & 2. GREEN & \cellcolor[HTML]{FFC702}2. ORANGE & 2 \\ \hline
Thank you for help.
PS Sorry for my English.
- Attachments
-
- table.png (66.72 KiB) Viewed 20164 times
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
Table with background color
welcome to the forum!
Yes, please upload the source code as a minimal compilable example, so we can test it. We don't see the table column settings and other commands, maybe you use
\cline
which could cause this, in contrast to \hline
normally.As a remark: such grid tables are very bad to read. Some people think that tables must look like Excel tables, but even in Excel the grid is for inputting data, not for printing and reading. Such boxed cells are bad for reading. A very good style is using no blocking lines at all, maybe only a few horizontal lines below and above and separating the header. But no vertical lines if the reading flow is horizontal.
A table sample showing what I mean by using few lines:
Code: Select all
% Stefan Kottwitz, LaTeX Cookbook, Packt Publishing, 2015
% Chapter 5, Designing Tables
% Merging cells
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{metalogo}
\renewcommand{\arraystretch}{1.6}
\begin{document}
\begin{tabular}{@{}p{1.5cm}p{1.6cm}>{\raggedleft}p{1cm}
>{\raggedright}p{1.6cm}r@{}}
Compiler & \multicolumn{2}{c}{Input}
& \multicolumn{2}{c}{Output} \\
\cmidrule(r){1-1}\cmidrule(lr){2-3}\cmidrule(l){4-5}
& Encoding & Images & Fonts & Format \\
\cmidrule(lr){2-2}\cmidrule(lr){3-3}
\cmidrule(lr){4-4}\cmidrule(l){5-5}
\LaTeX & utf8, ascii, applemac, latin1, \ldots
& EPS & Type 1, Type 3 & DVI \\
pdf\LaTeX & utf8, ascii, applemac, latin1, \ldots
& PDF PNG JPG & Type 1, Type 3 & PDF \\
\XeLaTeX, \LuaLaTeX & utf8
& PDF PNG JPG & Type 1, Type 3,
OpenType, Graphite, TrueType & PDF \\
\end{tabular}
\end{document}
Code: Select all
% Stefan Kottwitz, LaTeX Cookbook, Packt Publishing, 2015
% Chapter 5, Designing Tables
% Coloring a table
\documentclass{article}
\usepackage[table]{xcolor}
\rowcolors{2}{gray!15}{white}
\newcommand{\head}[1]{%
\textcolor{white}{\textbf{#1}}}
\renewcommand{\arraystretch}{1.5}
\pagestyle{empty}
\begin{document}
\begin{table}[ht]
\centering
\sffamily
\begin{tabular}{rlr}
\rowcolor{black!75}
& \head{Distribution} & \head{Hits} \\
1 & Mint & 2364 \\
2 & Ubuntu & 1838 \\
3 & Debian & 1582 \\
4 & openSUSE & 1334 \\
5 & Fedora & 1262 \\
6 & Mageia & 1219 \\
7 & CentOS & 1171 \\
8 & Arch & 1040 \\
9 & elementary & 899 \\
10 & Zorin & 851 \\
\end{tabular}
\end{table}
\end{document}

Stefan
Re: Table with background color
I've already solved this problem.
Horizontal lines are not showing only on monitor. When I print the table everything is OK.
