2

I need to fill out some Word form. As the form is very long I was allowed to transform it into a LaTeX format. One item that is difficult for me to mimic are the tables. They look like this:

enter image description here

Note that word is using a specific spacing as well as a different background color it would be great to mimic both a closely as possible.

I am aware of the table generator for LaTeX. https://www.tablesgenerator.com/ But that does not help me with either the spacing nor the background color.

Follow-Up Question: In the two very nice answers it is also possible to edit the colors. I know the RGB values of the specific colors that I want to use. How can I set the colors using RGB values? the predefined colors are not exactly matching my needs.

2
  • 1
    Welcome to TeX.SE! Can you show us the TeX code you tried so far?
    – Mensch
    Oct 3 '21 at 20:46
  • 2
    as far as I have seen by examples posted previously on thi ssite the tablesgenerator website makes massively over complicated markup and would be best avoided. for your table you can copy the examples in the colortbl manual (texdoc colortbl although that uses more cheerful colours than just grey:-) Oct 3 '21 at 20:52
8

With the help of the tabularray package, you can quite easily get a similar output:

enter image description here

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\noindent
\begin{tblr}{
 width=\linewidth,
 colspec={X[2]X[3]},
 hlines ={gray7},
 vlines ={gray7},
 row{1} = {bg=gray9, fg=azure4, font=\sffamily},
 column{1} = {gray9, fg=azure4, font=\sffamily},
}
 first column header   & second column header  \\
 row 1 & contents   \\
 row 2 & more text here    \\
 row 3 & other longer text in this cell other longer text in this cell other longer text in this cell \\
 row 4 & text   \\
 row 5 & example text \\
\end{tblr}

\end{document}
3
  • 1
    Finally, changing the font to Calibri will make the camouflage perfect =) Oct 4 '21 at 0:01
  • Nice, but my overleaf compiler says it cannot find tabularray. I use Xelatex, as I need to important the Calibri font and that does not work with pdflatex.
    – Till
    Oct 4 '21 at 9:55
  • 2
    @Till tabulararray package is not yet added in Overleaf. Try adding it manually. You can find it here. Also, you might need to add the ninecolors package.
    – Imran
    Oct 4 '21 at 10:20
4

With the nicematrix package.

output

MWE:

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\begin{table}[htbp]
    \sffamily 
    %\caption{Caption}
    \label{tab:my_label}
    \centering
    \begin{NiceTabular}{|>{\color{blue}}m{4.5cm}|m{6.5 cm}|}[hvlines, rules/color=gray!70, cell-space-limits=3pt]
    \CodeBefore
    \columncolor{gray!20}{1}
    \Body
    \RowStyle{\color{blue}}Experience & Number of months\\
    Research activities & Some text\\
    Education & Some text\\
    Leave & Some text\\
    Management tasks & Some text\\
    Others (please specify): & Some text\\
    \end{NiceTabular}
    
\end{table}

\end{document}

Edit: I wasn't notified about your edit in the question and probably the answerers aren't notified about any edit in the question as @leandriis hasn't also noticed yet.

You can easily set colors using RGB values. For absolute RGB values, you can use the syntax [RGB]{num, num, num} and for relative RGB values (i.e. R/255, G/255, B/255), you can use the syntax [rgb]{frac, frac, frac}.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{xcolor}

\begin{document}
\begin{table}[htbp]
    \sffamily 
    %\caption{Caption}
    \label{tab:my_label}
    \centering
    \begin{NiceTabular}{|>{\color[RGB]{20, 40, 200}}m{4.5cm}|m{6.5 cm}|}[hvlines, rules/color=gray!70, cell-space-limits=3pt]
    \CodeBefore
    \columncolor[RGB]{224, 224, 224}{1}
    \Body
    \RowStyle{\color[rgb]{0.08, 0.08, 0.86}}Experience & Number of months\\
    Research activities & Some text\\
    Education & Some text\\
    Leave & Some text\\
    Management tasks & Some text\\
    Others (please specify): & Some text\\
    \end{NiceTabular}
    
\end{table}

\end{document}

RGB output

1
  • @Till extended the answer to add color using RGB values.
    – Imran
    Nov 10 '21 at 11:34

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.