1

In the following, there is an issue in the colouring of the first line. It should be a one simple grey block but there is some overlaying white rectangle.

Why and how to fix it?

\documentclass{article}

\usepackage{amsfonts}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{wasysym}

\begin{document}

\begin{tabular}{@{} m{2cm} <{\hspace*{1mm}} | m{1.9cm} <{\hspace*{1mm}}}
\multicolumn{2}{c}{\cellcolor{black!20!white}{}}\\[-3mm]
\multicolumn{2}{c}{\cellcolor{black!20!white}{\footnotesize $\ \mathbf{15}$ \hspace{0pt plus 1filll} Test}}\\[1.5mm]
\scriptsize \hfill $\times \hspace{-1pt}\approx\hspace{-1pt}\checked$
& \scriptsize \hfill $\times \hspace{-1pt}\approx\hspace{-1pt}\checked$  \\                                                          
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\[3mm]
\end{tabular}

\end{document}

enter image description here

Log

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex) \write18 enabled. entering extended mode (./bac_a_sable.tex LaTeX2e <2017-04-15> Babel <3.10> and hyphenation patterns for 84 language(s) loaded. (/usr/local/texlive/2017/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/local/texlive/2017/texmf-dist/tex/latex/base/size10.clo)) (/usr/local/texlive/2017/texmf-dist/tex/latex/amsfonts/amsfonts.sty) (/usr/local/texlive/2017/texmf-dist/tex/latex/tools/tabularx.sty (/usr/local/texlive/2017/texmf-dist/tex/latex/tools/array.sty)) (/usr/local/texlive/2017/texmf-dist/tex/latex/xcolor/xcolor.sty (/usr/local/texlive/2017/texmf-dist/tex/latex/graphics-cfg/color.cfg) (/usr/local/texlive/2017/texmf-dist/tex/latex/graphics-def/pdftex.def (/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/infwarerr.sty) (/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)) (/usr/local/texlive/2017/texmf-dist/tex/latex/colortbl/colortbl.sty)) (/usr/local/texlive/2017/texmf-dist/tex/latex/wasysym/wasysym.sty) (./bac_a_sable.aux) (/usr/local/texlive/2017/texmf-dist/tex/context/base/mkii/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] ) (/usr/local/texlive/2017/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/local/texlive/2017/texmf-dist/tex/latex/amsfonts/umsb.fd) (/usr/local/texlive/2017/texmf-dist/tex/latex/wasysym/uwasy.fd) [1{/usr/local/t exlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./bac_a_sable.aux) )< /usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb> Output written on bac_a_sable.pdf (1 page, 42174 bytes). SyncTeX written on bac_a_sable.synctex.gz. Transcript written on bac_a_sable.log.

3

3 Answers 3

4

If I understand well, what you are trying to achieve, it's much simpler to use a single row for the table head, and the cellspace package to increase the row height! The problem was using two \multicolumns with different alignments, or hspace specifications. i.e., remove the '{0 plus 1fill}'. Possibly, \multicolumn{2}{c}{\cellcolor{black!20!white}{\footnotesize $\ \mathbf{15} $ \hspace{1.5mm} {\bf Test}}}\\

See below, for a possible alternative/correction using the cellspace package:

\documentclass{article}

\usepackage{amsfonts}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{8pt}
\setlength{\cellspacebottomlimit}{8pt}
\usepackage{wasysym}

\begin{document}

\begin{tabular}{@{} m{2cm} <{\hspace*{1mm}} | m{1.9cm} <{\hspace*{1mm}}}
\rowcolor{black!20!white}\multicolumn{1}{@{}Sl}{\footnotesize $\ \mathbf{15} $} & \multicolumn{1}{r}{\footnotesize Test}\\
\scriptsize \hfill $\times \hspace{-1pt}\approx\hspace{-1pt}\checked$
& \scriptsize \hfill $\times \hspace{-1pt}\approx\hspace{-1pt}\checked$ \\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\[3mm]
\end{tabular}

\end{document}

enter image description here

2
  • Thanks Bernard. Where Can I find more info on \multicolumn{1}{@{}Sl} (esp. the Sl)?
    – Colas
    Commented Jul 7, 2018 at 18:03
  • The prefix S defines a minimal vertical spacing at the top and bottom of cells in columns with specifier prefiexed with this letter. If you load siunitx, which defines an S column type, you have to use the letter C. You'll find some other details in the package documentation. On the other hand, \multicolumn here is also used to remove the vertical rule in the table header.
    – Bernard
    Commented Jul 7, 2018 at 18:27
3

enter image description here

\documentclass{article}
\usepackage{amssymb}
\usepackage{wasysym}
\usepackage[table]{xcolor}

\begin{document}

{\renewcommand\arraystretch{1.5}
 \newcommand\mcbf[2]{\multicolumn{1}{#1}{\normalsize\textbf{#2}}}
    \begin{tabular}{@{} >{\raggedleft\arraybackslash\scriptsize}p{2cm} <{\hspace*{1mm}} | 
                        >{\raggedleft\arraybackslash\scriptsize}p{2cm} <{\hspace*{1mm}}}
\rowcolor{black!20!white}
\mcbf{l}{15}  &   \mcbf{r}{Test}              \\
$\times \hspace{-1pt}\approx\hspace{-1pt}\checked$
                    &   $\times \hspace{-1pt}\approx\hspace{-1pt}\checked$  \\
\dotfill $\square$\,$\square$\,$\square$ & \dotfill $\square$\,$\square$\,$\square$\\
\dotfill $\square$\,$\square$\,$\square$ & \dotfill $\square$\,$\square$\,$\square$\\
\dotfill $\square$\,$\square$\,$\square$ & \dotfill $\square$\,$\square$\,$\square$
\end{tabular}
}
\end{document}
3
  • Let me check your code. I need the lines to be compact...
    – Colas
    Commented Jul 7, 2018 at 17:18
  • There should be no separator in the first line (the grey one).
    – Colas
    Commented Jul 7, 2018 at 17:19
  • 1
    @Colas, now i remove vertical line in gray row.
    – Zarko
    Commented Jul 7, 2018 at 17:48
1

In {NiceTabular} of nicematrix, you have a key cell-space-limits (inspired by the parameters of the package cellspace) that you can change for only one row (here the first row) by using the command \RowStyle.

In the following code, I have used \RowStyle also for the background and the size of the font in the first row.

I have changed the horizontal alignment of the text "Test" by using the command \Block (built-in in {NiceTabular}) : \Block[r]{}{Test}.

\documentclass{article}
\usepackage{amsfonts}
\usepackage{nicematrix}
\usepackage{wasysym}

\begin{document}

\begin{NiceTabular}{@{} m[l]{2cm} <{\hspace*{1mm}} | m{1.9cm} <{\hspace*{1mm}}}
\RowStyle[rowcolor=black!20!white,cell-space-limits=8pt]{\footnotesize}
\Block{1-2}{} % to prevent the vertical rule in the first row
\ $\mathbf{15} $ & \Block[r]{}{Test}\\
\scriptsize \hfill $\times \hspace{-1pt}\approx\hspace{-1pt}\checked$
& \scriptsize \hfill $\times \hspace{-1pt}\approx\hspace{-1pt}\checked$ \\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\
\dotfill\scriptsize $\square$\,$\square$\,$\square$ & \dotfill\scriptsize $\square$\,$\square$\,$\square$\\[3mm]
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

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