1

Is there a Code to make a table like this in latex?

enter image description here

I am currently using the following code, I would like to set first row as color grey

\usepackage{colortbl}

\documentclass[a4paper,11pt]{article}
\begin{table}[h]
    \centering
    \begin{tabular}{|>{\columncolor[gray]{0.8}}c|c|c|c|c|c|c|c|}
        \hline
        128&64&32&16&8&4&2&1\\\hline
        1&0&1&1&0&1&0&1\\\hline
        1&0&1&1&0&1&0&1\\\hline
    \end{tabular}
\end{table}
\end{document}
4
  • There are many possibilities. Why don't you start some simple code using tabular and we'll take from there to help setting the colors, alignment, widths, etc. Commented Jul 14, 2021 at 17:30
  • @SimonDispa you are true, I have update code I am trying to personalize
    – Python
    Commented Jul 14, 2021 at 17:38
  • Good start! I suggest you fill the content of the cells, all text and numbers, including those with decimal point. Otherwise a simple answer will not work for you in the real world. Start your code with \documentclass{..} because the layout of the page will matter later. Do not spend time with colors yet. Size and alignment comes first. Commented Jul 14, 2021 at 18:51
  • There are some interesting aspects to the table (coloring, multiple lines in the header). There are also some boring and easy aspects to the table (typing the text for those headers, entering the numbers). You are more likely to get good answers to the hard parts if you go to the trouble of doing the easy parts. (Also, are your decimal numbers all ending in .00? That makes things simpler, but then there are solutions that won't work if you switch from that ending.)
    – Teepeemm
    Commented Jul 14, 2021 at 20:44

1 Answer 1

0

As starting point:

enter image description here

In above table are used the following packages: booktabs (for \addlinespace between the first and the second table row), makecell˙(for columns' headers), threeparttable(for notes in table) andsiunitx` for formating numbers in the last four tables' columns.

\documentclass[a4paper,11pt]{article}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\usepackage{booktabs, makecell, threeparttable}    

\begin{document}
\begin{table}[ht]
    \begin{threeparttable}
    \begin{tabular}{|w{l}{4em}|l| 
                    S[table-format=2.0]|
                    S[table-format=3.2, table-column-width=4em]|
               *{2}{S[table-format=2.0, table-column-width=4em]|}
                   }  
    \rowcolor{black}
    \multicolumn{6}{c}{\textcolor{white}{some text}}        \\
    \addlinespace
    \hline
    \rowcolor{gray!80}
\makecell[l]{WP\\ Number\tnote{53}}
    &   WP Title        
        &   {\makecell{Lead\\ benefeciary\\ number\tnote{55}}}
            &   {\makecell{Person-\\ moths\tnote{56}}}
                &   {\makecell{Start\\ month\tnote{57}}}
                    &   {\makecell{End\\ month\tnote{58}}}  \\
    \hline
WP 1& package 1 title
        &  7 & 171.00 &  1 & 36     \\
    \hline
WP 2& package 2 title
        &  6 & 192.00 &  1 & 36     \\
    \hline
WP 3& package 3 title
        & 26 & 102.00 &  2 & 36     \\
    \hline
WP 4& package 4 title
        & 13 &  73.00 &  1 & 36     \\
    \hline
WP 5& package 5 title
        & 21 &  72.00 &  1 & 36     \\
    \hline
WP 6& package 6 title
        &  1 &  48.00 &  1 & 36     \\
    \hline
\multicolumn{2}{r|}{}
    & {\cellcolor{gray!80} Total}
             & \cellcolor{gray!80} 658.00
                      & \multicolumn{2}{l}{}   \\
    \cline{3-4}
    \end{tabular}
\begin{tablenotes}[flushleft]\footnotesize
\item[53]   some explanation
\item[55]   some explanation
\item[56]   some explanation
\item[57]   some explanation
\item[58]   some explanation
\end{tablenotes}
    \end{threeparttable}
\end{table}
\end{document}

Real text in the second column is left to OP to write it.

Addendum: As exercise, this table can be written by use of the tabularray package. This new table packages, here is used version L, has a bit different syntax which enables separating table formatting from its content. Its details are described in the package's documentation (which is part of its installation or can be find by help of the Google):

\documentclass[a4paper,11pt]{article}
\usepackage[table]{xcolor}

\usepackage{tabularray}  
\UseTblrLibrary{siunitx}

\begin{document}

\vspace*{21\baselineskip}
\begin{table}[ht]
    \begin{tblr}{hline{1-9},
                 hline{2} = {white, 3pt},
                 vline{1,2,6,7} = {1-8}{solid},
                 vline{3-5} = {1-9}{solid},
                 colspec = {X[0.9,m] l
                            X[m,c,si]
                            X[m,c,si]
                            X[m,c,si]
                            X[m,c,si]},
                row{1} = {bg=black,fg=white},
                row{2} = {bg=gray!80, font=\small\linespread{0.84}\selectfont},
                }
    \multicolumn{6}{c}{\textcolor{white}{some text}}    \\
{WP\\ Number\footnotemark[53]}
    &   WP Title
        &   {{{Lead\\ benefeciary\\ number\footnotemark[55]}}}
            &   {{{Person-\\ moths\footnotemark[56]}}}
                &   {{{Start\\ month\footnotemark[57]}}}
                    &   {{{End\\ month\footnotemark[58]}}}  \\
WP 1& package 1 title
        &  7 & 171.00 &  1 & 36     \\
WP 2& package 2 title
        &  6 & 192.00 &  1 & 36     \\
WP 3& package 3 title
        & 26 & 102.00 &  2 & 36     \\
WP 4& package 4 title
        & 13 &  73.00 &  1 & 36     \\
WP 5& package 5 title
        & 21 &  72.00 &  1 & 36     \\
WP 6& package 6 title
        &  1 &  48.00 &  1 & 36     \\
    &   & \SetCell{bg=gray!80} {{{Total:}}}
             & \SetCell{bg=gray!80} 658.00
                      &    &        \\
    \cline{3-4}
    \end{tblr}
\end{table}
\footnotetext[53]{\ some explanation}
\footnotetext[55]{\ some explanation}
\footnotetext[56]{\ some explanation}
\footnotetext[57]{\ some explanation}
\footnotetext[58]{\ some explanation}
\end{document}

Result is similar as before:

enter image description here

You must log in to answer this question.

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