Graphics, Figures & TablesThicker lines, center-align cells and background color of table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Thicker lines, center-align cells and background color of table

Post by bstex »

Hi,
as you see in the image, I need to make 3 changes to my table.
1. Make 5 lines of table thicker.
2. Make some cells to have their text center-aligned vertically.
3. Put background color on some rows.
mwe.png
mwe.png (88.95 KiB) Viewed 3245 times
My MWE code is:

Code: Select all

\documentclass[a4paper]{book} 
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}%
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
\usepackage{multirow}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{|>{\centering\arraybackslash} m{4em}|>{\centering\arraybackslash} m{5.5em}|R{2em}m{3em}|>{\centering\arraybackslash} C{5em}|>{\centering\arraybackslash} m{1ex}|>{\centering\arraybackslash} m{5.5em}|>{\centering\arraybackslash} m{5.5em}|}
\cline{1-5} \cline{7-8}
\multicolumn{5}{|c|}{\textbf{Text1}} &   & \multicolumn{2}{c|}{\textbf{Text2}} \\ \cline{1-5} \cline{7-8} 
\begin{tabular}[c]{@{}c@{}}Text3\\Text4\\Text5\end{tabular} & \begin{tabular}[c]{@{}c@{}}Text6\\Text7\\Text8\end{tabular} & \multicolumn{2}{c|}{\begin{tabular}[c]{@{}c@{}}Text9\\Text10\\Text11\end{tabular}} & \begin{tabular}[c]{@{}c@{}}Text12\\Text13\\Text14\end{tabular} & \multicolumn{1}{c|}{} & \begin{tabular}[c]{@{}c@{}}Text15\\Text16\end{tabular} & \begin{tabular}[c]{@{}c@{}}Text17\\Text18\end{tabular}\\ \cline{1-5} \cline{7-8}\noalign{\vskip.4pt}
1 A   & 1 A1 & 1 & A1   & 2  &   & A1 text & A text    \\ \cline{1-5} \cline{7-8} 
\multirow{2}{*}{2 B} & 2 B1 & 2 & B1   & 2  &   & B1 text & \multirow{2}{*}{B text}  \\ \cline{2-5} \cline{7-7}
   & 2 B2 & \textbf{\begin{tabular}[c]{@{}r@{}}1\\ 2\\ 3\end{tabular}} & \begin{tabular}[c]{@{}l@{}}B2a\\ B2b\\ B2c\end{tabular} & \textbf{\begin{tabular}[c]{@{}c@{}}2\\ 2\\ 2\end{tabular}}     &   & B2 text & \\ \cline{1-5} \cline{7-8} 
\multirow{3}{*}{3 C} & 3 C1 & 1 & C1   & 2  &   & C1 text & \multirow{3}{*}{C text}  \\ \cline{2-5} \cline{7-7}
   & 3 C2 & \textbf{\begin{tabular}[c]{@{}r@{}}1\\ 2\\ 3\end{tabular}} & \begin{tabular}[c]{@{}l@{}}C2a\\ C2b\\ C2c\end{tabular} & \textbf{\begin{tabular}[c]{@{}c@{}}2\\ 2\\ 2\end{tabular}}     &   & C2 text & \\ \cline{2-5} \cline{7-7}
   & 3 C3 & \textbf{\begin{tabular}[c]{@{}r@{}}1\\ 2\\ 3\\ 4\\ 5\end{tabular}} &   & \textbf{\begin{tabular}[c]{@{}c@{}}2\\ 2\\ 2\\ 2\\ 2\end{tabular}}   &   & C3 text & \\ \cline{1-5} \cline{7-8} 
\multirow{4}{*}{4 D} & 4 D1 & 1 & D1   & 2  &   & D1 text & \multirow{4}{*}{D text} \\ \cline{2-5} \cline{7-7}
   & 4 D2 & \textbf{\begin{tabular}[c]{@{}r@{}}1\\ 2\\ 3\end{tabular}} & \begin{tabular}[c]{@{}l@{}}D2a\\ D2b\\ D2c\end{tabular} & \textbf{\begin{tabular}[c]{@{}c@{}}2\\ 2\\ 2\end{tabular}}     &   & D2 text & \\ \cline{2-5} \cline{7-7}
   & 4 D3 & \textbf{\begin{tabular}[c]{@{}r@{}}1\\ 2\\ 3\\ 4\\ 5\end{tabular}} &   & \textbf{\begin{tabular}[c]{@{}c@{}}2\\ 2\\ 2\\ 2\\ 2\end{tabular}}   &   & D3 text & \\ \cline{2-5} \cline{7-7}
   & 4 D4 & \textbf{\begin{tabular}[c]{@{}r@{}}1\\ 2\\ 3\\ 4\\ 5\\ 6\\ 7\end{tabular}} &   & \textbf{\begin{tabular}[c]{@{}c@{}}2\\ 2\\ 2\\ 2\\ 2\\ 2\\ 2\end{tabular}} &   & D4 text & \\ \cline{1-5} \cline{7-8} 
\end{tabular}
\end{table}

\end{document}
Any help, please?

Recommended reading 2024:

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

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Thicker lines, center-align cells and background color of table

Post by Johannes_B »

A program generated the code for this table, right? It is close to impossible for a sane human being to modify auto-generated code.

There are already \multirows used in the table, use them for center aligning the other cells as well.

No idea how to get the lines thicker, never needed this. Maybe package hhline has something in stock.

You can use package colortbl by passing the option table to package xcolor.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Thicker lines, center-align cells and background color of table

Post by bstex »

Johannes_B wrote:It is close to impossible for a sane human being to modify auto-generated code.
Then, we are totally screwed with AI. :lol:

I'll try all of your advices.
At last, if I will not succeed, I will put this table in my book as image. ;)
Thank you so much!
Post Reply