2

I have been formatting the table on the first picture for a long time and still can not achieve a desirable result shown in the second picture.

I am trying to solve 2 problems:

  1. I can't get why my table white borders are mostly not visible. It's interesting that in the Overleaf online generator I can see the white borders but if I print the PDF out it looks different.
    My Overleaf example

  2. The text is not vertically-centered of the cells. It's a bit too down.

Table comparsion: (updated) Tables

\documentclass[8pt]{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage{graphicx}  \usepackage[paperwidth=841pt,paperheight=595pt,top=28pt,right=28pt,bottom=28pt,left=28pt, includefoot, includehead]{geometry}
\usepackage{tabularx} 
\usepackage{listings}
\usepackage{color}  
% SET FONT
\usepackage[T1]{fontenc}
\usepackage[scaled=0.9]{helvet}
\renewcommand*{\familydefault}{\sfdefault}
% TABLES SETTING
\usepackage[font={color=darkgray,bf}]{caption} % set style of all captions
\usepackage[tablename=SAMPLE TABLE]{caption} % set default name of the table

\definecolor{lightergray}{HTML}{f4f4f4}
\definecolor{lightgray}{HTML}{ededed}
\definecolor{myPurple}{HTML}{af0c42}

\begin{document}     
\bigskip
{\renewcommand{\arraystretch}{2} % table padding
\begin{table}[h]
\arrayrulecolor{white}
\caption{\hfill\mbox{}} % to move caption of table to left
\rowcolors{2}{lightergray}{lightgray} % color for every odd and even rows
\begin{tabularx}{\textwidth}{|m{1cm}|m{5cm}|m{2.5cm}|m{1.5cm}|m{2cm}|m{2cm}|m{10.6cm}|}
\hline\rowcolor{myPurple} 
{\color[HTML]{FFFFFF} Key} & {\color[HTML]{FFFFFF} Name} & {\color[HTML]{FFFFFF} Data type} & {\color[HTML]{FFFFFF} Max. \newline length} & {\color[HTML]{FFFFFF} Is nullable} & {\color[HTML]{FFFFFF} Default value} & {\color[HTML]{FFFFFF} Description} \\ \hline
\includegraphics[scale=0.45]{PK.png} & OID & int &  & False &  &  \\ \hline
\includegraphics[scale=0.45]{FK.png} & Url & nvachar & 255 & True &  &  \\ \hline
\includegraphics[scale=0.45]{FK.png} & ServerFolder & nvachar & 255 & True &  &  \\ \hline
\includegraphics[scale=0.45]{FK.png} & OptimisticLockField & int &  & True &  &  \\ \hline
\includegraphics[scale=0.45]{FK.png} & GCRecord & int &  & True &  &  \\ \hline   
\end{tabularx}
\end{table}
} 
\end{document}

I don't know what I have done wrong. Could someone help me with that, please?

  • I don't really se the difference. Perhaps there are details I can't see at this scaling. Could you explain more? – Bernard Nov 5 '18 at 22:43
  • I have just updated the pictures. I hope it is more visible. Notice that in my table miss some white gaps. If you download PDF from Overleaf link you can see how bad it is looking. – Ikaros1x2 Nov 5 '18 at 23:05
3

I propose replacing the use of \arraystretch (which is asymmetric) with the cellspace package. It lets you define a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you load siunitx). So I defined a Mcolumn type which includes this prefix. B.t.w. you use a tabularx environment, but have no X column, which is problematic.

For the cell borders, I just changed the value of \arrayrulewidth:

\documentclass[8pt]{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage{graphicx}
 \usepackage[paperwidth=841pt,paperheight=595pt,top=28pt,right=28pt,bottom=28pt,left=28pt, includefoot, includehead]{geometry}
\usepackage{tabularx}
\usepackage{listings}
% SET FONT
\usepackage[T1]{fontenc}
\usepackage[scaled=0.9]{helvet}
\renewcommand*{\familydefault}{\sfdefault}
% TABLES SETTING
\usepackage[font={color=darkgray,bf}]{caption} % set style of all captions
\usepackage[tablename=SAMPLE TABLE]{caption} % set default name of the table

\definecolor{lightergray}{HTML}{f4f4f4}
\definecolor{lightgray}{HTML}{ededed}
\definecolor{myPurple}{HTML}{af0c42}

\usepackage{cellspace} 
\setlength{\cellspacetoplimit}{10pt}
\setlength{\cellspacebottomlimit}{10pt}% table padding
\newcolumntype{M}[1]{ >{\mbox{}}S{m{#1}}}

\begin{document}
\bigskip

\begin{table}[h]
\arrayrulecolor{white}\arrayrulewidth=1pt
\caption{\hfill\mbox{}} % to move caption of table to left
\rowcolors{2}{lightergray}{lightgray} % color for every odd and even rows
\begin{tabularx}{\textwidth}{|m{1cm}|M{5cm}|M{2.5cm}|M{1.5cm}|M{2cm}|M{2cm}|>{\arraybackslash}M{10.6cm}|}
\hline\rowcolor{myPurple}
{\color[HTML]{FFFFFF} Key} & {\color[HTML]{FFFFFF} Name} & {\color[HTML]{FFFFFF} Data type} & {\color[HTML]{FFFFFF} Max. \newline length} & {\color[HTML]{FFFFFF} Is nullable} & {\color[HTML]{FFFFFF} Default value} & {\color[HTML]{FFFFFF} Description} \\ \hline
 & OID & int & & False & & \\ \hline
 & Url & nvachar & 255 & True & & \\ \hline
 & ServerFolder & nvachar & 255 & True & & \\ \hline
 & OptimisticLockField & int & & True & & \\ \hline
 & GCRecord & int & & True & & \\ \hline
\end{tabularx}
\end{table}

\end{document} 

enter image description here

|improve this answer|||||
3

maybe you liked this some how different approach:

  • for including images in table are used macro \adjustimage from ˙the adjustbox package
  • with \adjustboxset are defined image baseline to its vertical center as well as additional vertical space around them
  • the column types are changed with exception for the last column to p{<width>}
  • for the last column is not clear, if their cells will have multi line text or not and how it should be aligned. in mwe below is assumed, that it is multi line and should be vertically centered
  • for shorter writing of the text color in colored cells is defined new color name wht (for white)
  • coloring of cells in the first row is used \rowcolor which for this row overwrite table color presenting. ny this the code for table is shorter and more clear (t list for my opinion)

main changes in mwe below in comparison to your code are in code indicated by <--

\documentclass[8pt]{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage[paperwidth=841pt,paperheight=595pt,
            margin=28pt, includefoot, includehead]{geometry}
\usepackage{adjustbox}   % <--- instead of includegraphicx
\usepackage{tabularx}
% SET FONT
\usepackage[T1]{fontenc}
\usepackage[scaled=0.9]{helvet}
\renewcommand*{\familydefault}{\sfdefault}
% TABLES SETTING
\usepackage[font={color=darkgray,bf}]{caption} % set style of all captions
\usepackage[tablename=SAMPLE TABLE]{caption} % set default name of the table

\definecolor{lightergray}{HTML}{f4f4f4}
\definecolor{lightgray}{HTML}{ededed}
\definecolor{myPurple}{HTML}{af0c42}

\definecolor{wht}{HTML}{FFFFFF}     % <--- new

\usepackage{lipsum}

\begin{document}
\begin{table}[h]
    \arrayrulecolor{white}
    \adjustboxset{width=\linewidth,valign=c, margin=0pt 3pt 0pt 3pt} % <-- new
\caption{\hfill\mbox{}} % to move caption of table to left
    \rowcolors{2}{lightergray}{lightgray} % color for every odd and even rows
\begin{tabularx}{\textwidth}{|p{1cm}|p{5cm}|p{2.5cm}|p{1.5cm}|p{2cm}|p{2cm}|m{10.6cm}|}
    \hline\rowcolor{myPurple}
\textcolor{wht}{Key}
     &  \textcolor{wht}{Name} 
        &   \textcolor{wht}{ata type} 
            &   \begin{tabular}{>{\color{wht}}l}    % <--- new
                Max.\\ 
                length
                \end{tabular} 
                &   \textcolor{wht}{Is nullable} 
                    &   \textcolor{wht}{Default value} 
                        &   \textcolor{wht}{Description}    \\
    \hline
\adjustimage{}{example-image-duck}  
    & OID           & int       &       & False &   & \lipsum[11] \\ \hline
%
\adjustimage{}{example-image-duck}  
    & Url           & nvachar   & 255   & True  &   &  \\ \hline
\adjustimage{}{example-image-duck}  
    & ServerFolder  & nvachar   & 255   & True  &   &  \\ \hline
\adjustimage{}{example-image-duck}
    & OptimisticLockField   
                    & int       &       & True  &   &  \\ \hline
\adjustimage{}{example-image-duck}  
    & GCRecord      & int       &       & True  &   &  \\ \hline
\end{tabularx}
\end{table}
\end{document}

enter image description here

|improve this answer|||||

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.