1

I am new to LaTeX and trying to draw a table. I have followed a couple of guides and found solutions to problems I was having on here but I can't find anything to help me remove the white lines I have running through my table and to the left of the second row.

Please can someone help me?

Image of table with white lines

\documentclass[paper=a4, fontsize=11pt]{scrartcl}

\usepackage{multirow, booktabs} 
\usepackage{array} 
\usepackage[table]{xcolor} 

\newcolumntype{x}[1]{%
>{\centering\hspace{0pt}}p{#1}}%

\definecolor{myblue}{RGB}{122, 140, 213}

\renewcommand{\arraystretch}{1.5}
\begin{center}
\begin{tabular}{|x{3cm}|x{3.5cm}|x{3.5cm}| }\hline
\rowcolor{myblue!50}  & \multicolumn{2}{|c|}{Concentration of Sodium Hydroxide Added /M} \\ \cmidrule{2-3}
\rowcolor{myblue!50} \multirow{-2}{*}{Sample Number} & Drop 1 (left) & Drop 2 (Right)\tabularnewline\hline
 1 & 0.01 M & 1.00 M \tabularnewline\hline
 2 & 0.05 M & 0.10 M \tabularnewline\hline
 3 & 0.10 M & 0.01 M \tabularnewline\hline
 4 & 0.50 M & 0.05 M \tabularnewline\hline
 5 & 1.00 M & 0.50 M \tabularnewline\hline
\end{tabular}
\end{center}
1
  • Welcome to TeX.SE.
    – Mico
    Oct 22, 2019 at 13:18

4 Answers 4

1

I would use \hhline rather than \cmidrule, and split the \multicolumn in two lines:

\documentclass[paper=a4, fontsize=11pt]{scrartcl}

\usepackage{multirow, booktabs, hhline}
\usepackage{array, hhline}
\usepackage[table]{xcolor}

\newcolumntype{x}[1]{%
>{\centering\arraybackslash}p{#1}}%

\definecolor{myblue}{RGB}{122, 140, 213}

\begin{document}

\renewcommand{\arraystretch}{1.5}
\begin{center}\setlength{\aboverulesep}{0pt}\setlength{\belowrulesep}{0pt}
\begin{tabular}{|x{3cm}|x{3.5cm}|x{3.5cm}| }\hline
\rowcolor{myblue!50}[\tabcolsep][\dimexpr\tabcolsep +0.4pt] & \multicolumn{2}{p{\dimexpr7cm + 2\tabcolsep}|}{\centering Concentration of Sodium Hydroxide\newline Added /M} \\[-0.04 pt]
 \hhline{|>{\arrayrulecolor{myblue!50}}->{\arrayrulecolor{black}}|--|}\noalign{\vskip-0.04pt}
\rowcolor{myblue!50}\multirow{-2.}{*}{\cellcolor{myblue!50}Sample Number} & Drop 1 (left) & Drop 2 (Right)\tabularnewline
\hline
 1 & 0.01 M & 1.00 M \\ \hline
 2 & 0.05 M & 0.10 M \\ \hline
 3 & 0.10 M & 0.01 M \\ \hline
 4 & 0.50 M & 0.05 M \\ \hline
 5 & 1.00 M & 0.50 M \\ \hline
\end{tabular}
\end{center}

\end{document} 

enter image description here

1
  • Thank you! that has worked!
    – JM1553
    Oct 23, 2019 at 9:51
3

I would remove not only the white line but also (a) all vertical rules and (b) almost all horizontal lines. Your table will be much more readable as a result of the proposed simplifications.

enter image description here

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage{multirow, booktabs, array}
\usepackage[table]{xcolor}
\definecolor{myblue}{RGB}{122, 140, 213}

\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}
\renewcommand{\arraystretch}{1.25}

\begin{document}
\begin{center}
\begin{tabular}{x{3cm}x{4cm}x{4cm} }
\rowcolor{myblue!50}  & 
\multicolumn{2}{c}{Concentration of Sodium Hydroxide Added /M} \\ 
\rowcolor{myblue!50} \multirow{-2}{*}{Sample Number} 
& Drop 1 (left) & Drop 2 (right) \\
 1 & 0.01 M & 1.00 M \\
 2 & 0.05 M & 0.10 M \\
 3 & 0.10 M & 0.01 M \\
 4 & 0.50 M & 0.05 M \\
 5 & 1.00 M & 0.50 M \\
\bottomrule % <-- new
\end{tabular}
\end{center}
\end{document}
2
  • Molarity units provided for each data entry also seem redundant as the header explicitly states them (…/M – "over mole per litre"). Going even more minimalist, one can also get rid of the color as it doesn't really highlight anything: the header is well visible by \hlines/\midrules anyway.
    – andselisk
    Oct 22, 2019 at 13:40
  • 1
    Thank you. I prefer to keep some of the lines in as in some of my larger tables it breaks the data up and I like to be consistent across all tables. Thanks for pointing out I still had M in the table - it was from an earlier iteration before i figured out the \multicolumn feature!
    – JM1553
    Oct 22, 2019 at 13:58
0

I take it you are using \cmidrule because \cline gets covered with color. The good news is that the gaps above and below \cmidrule can be set using \aboverulesep and \belowrulesep. The bad news is that I haven't figured out how to make temporary changes in the middle of the tabular without getting a "misplaced \noalign" error.

Now the only problem is the gap due to the \multicolumn being wider than the normal columns.

\documentclass[paper=a4, fontsize=11pt]{scrartcl}

\usepackage{multirow, booktabs} 
\usepackage{array} 
\usepackage[table]{xcolor} 

\begin{document}

\newcolumntype{x}[1]{%
>{\centering\hspace{0pt}}p{#1}}%

\definecolor{myblue}{RGB}{122, 140, 213}

\renewcommand{\arraystretch}{1.5}
\begin{center}
\aboverulesep=0pt
\belowrulesep=0pt
\begin{tabular}{|x{3cm}|x{3.5cm}|x{3.5cm}| }\hline
\rowcolor{myblue!50}  & \multicolumn{2}{c|}{Concentration of Sodium Hydroxide Added /M} \\
\cmidrule{2-3}
\rowcolor{myblue!50} \multirow{-2}{*}{Sample Number} & Drop 1 (left) & Drop 2 (Right) \rule{0pt}{\dimexpr \arraystretch\ht\strutbox+2pt}
\tabularnewline\hline
 1 & 0.01 M & 1.00 M \tabularnewline\hline
 2 & 0.05 M & 0.10 M \tabularnewline\hline
 3 & 0.10 M & 0.01 M \tabularnewline\hline
 4 & 0.50 M & 0.05 M \tabularnewline\hline
 5 & 1.00 M & 0.50 M \tabularnewline\hline
\end{tabular}
\end{center}
\end{document}

demo

0

Just for fun with TikZ.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\newcommand{\col}[6]{
\path #1  node{#2}
++(-90:1) node{#3}
++(-90:1) node{#4}
++(-90:1) node{#5}
++(-90:1) node{#6};
}% end of \col command
\begin{tikzpicture}[xscale=4,yscale=.6]
\begin{scope}[shift={(-.5,.5)}]
\draw[teal] 
(0,0) grid (3,-5)
(0,0) rectangle (3,2)
(1,1)--+(0:2) (1,0)--+(90:2) (2,0)--+(90:1);
\end{scope} 
\col{(0,0)}{1}{2}{3}{4}{5}
\col{(1,0)}{0.01 M}{0.05 M}{0.10 M}{0.50 M}{1.00 M}
\col{(2,0)}{1.00 M}{0.10 M}{0.01 M}{0.05 M}{0.50 M}
\path
(0,1.5) node{Sample Number}
(1,1)   node{Drop 1 (left)}
(2,1)   node{Drop 2 (right)}
(1.5,2) node{Concentration of Sodium Hydroxide Added /M};
\end{tikzpicture}
\end{document}

In the above code, if you use

\begin{scope}[shift={(-.5,.5)}]
\fill[cyan!30] (0,0) rectangle (3,2);
\draw[cyan] (0,-5)--+(0:3);
\end{scope} 

then you get

enter image description here

You must log in to answer this question.

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