0

I am trying to have different tables in my report. Some of them I need to have the headers one color (black with white text) and different rowcolor (Table 1).

While others I need only the headers to be coloured and that to be centered.

I have added my current code to overleaf and adding an image to what I am trying to achieve.

enter image description here

Could someone help me with this?

2

Here you are. The cells contents were already centred, so there was nothing to do. Note hyperref should be loaded as the last package, with very few exceptions (cleveref is such an exception).

\documentclass{article}
\usepackage[utf8]{inputenc}

%** latex setup**%
\usepackage[export]{adjustbox} %for fitting the tables
\usepackage[table]{xcolor}
\rowcolors{2}{gray!15}{white}

\usepackage{booktabs}
\usepackage{quotchap}
\usepackage[nottoc,notindex,notlot,notlof]{tocbibind}
\usepackage{multicol}
\usepackage{minitoc}
\usepackage{multirow}
\usepackage{wrapfig}

\definecolor{Gray}{gray}{0.85}
\definecolor{LightCyan}{rgb}{0.88,1,1}

\usepackage[font=small,labelfont=bf]{caption}
\usepackage{fancyhdr}
%\usepackage{times}
\usepackage{tikz}            % For drawing stuff
\usepackage{glossaries}      % For abbrevations 
\usepackage{acronym} 
\usepackage[most]{tcolorbox}
\usepackage{hyperref} %For adding hyperlinks

%** new commands**%
\newcommand{\head}[1]{%
    \textcolor{white}{\textbf{#1}}}
\renewcommand{\arraystretch}{1.5}
\renewcommand*{\sectfont}{\bfseries}


\title{Table Formating}
\begin{document}

\maketitle

\section{Table 1}
\begin{table}[!h]
    \centering
    \sffamily
    \caption{Table variant 1} \label{tb:1}
\begin{tabular}{|cccc|}
    \rowcolor{black!75}
    \head{\#} & \head{Layer Name }& \head{Cooper Thickness} & \head{Description} \\ 
    1 & Top Solder Mask &  & Solder Resist \\ 
    \hline 
    2 & Top Layer & 1.4 mil &  \\ 
\end{tabular} 
\end{table}

\section{Table Formating}


\begin{table}[!h]
    \centering
    \sffamily
\rowcolors{3}{}{}
    \caption{Table 2} \label{tb:2}
\begin{tabular}{c|c}
    \rowcolor{black!75}
    \head{PARAMETER} & \head{SPECIFICATIONS / COMMENTS }\\ 
    \multicolumn{2}{c}{\cellcolor{black!60}\head{TEMPERATURE SENSOR}} \\
    \hline 
    Sensor & ... \\ 
    \hline 
    Pressure sensor &  \\ 
    \hline 
    Name ... & ... \\ 
    \hline 
    Resolution & ...  \\ 
    \hline 
    Accelometer and Magnometer &  \\ 

\end{tabular} 
\end{table}

\end{document}

enter image description here

  • The code doesn't produce the table you showed as table 2. With your code, table 2 still has striped rows. It will work if you insert the following after \begin{table}[!h]: \rowcolors{1}{white}{white} – jaspast Mar 9 at 21:37
  • @jaspast: Sorry, it was a clipboard accident. I copied the O.p.s code instead of mine. It's fixed (\rowcolors... just before \begin{tabular}. Thanks for pointing it! – Bernard Mar 9 at 21:39
  • Hi, about centering. I would like the TEMPERATURE SENSOR to take the whole row and be centered. That's what I meant. Is this possible ? – user3874252 Mar 9 at 21:41
  • Yes, it is. Please see my updated code. – Bernard Mar 9 at 22:01
  • Thank you very much @Bernard! – user3874252 Mar 9 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.