0

Space under subheader w/ # and % are not even, why is this?

\begin{table}
\centering
\rowcolors{1}{}{lightgray}
\begin{tabular}{|l|c|c|c|c|c|c|}
\hline
\multicolumn{7}{|c|}{Sample QC} \\
\hline
\multicolumn{1}{|c|}{} & \multicolumn{2}{c|}{CoreExome-24 v1.0} & \multicolumn{2}{c|}{CoreExome-24 v1.0} & \multicolumn{2}{c|}{CoreExome-24 v1.1}\\
\cline{2-7}
\multicolumn{1}{|c|}{QC Flag} & \# & \% & \# & \% & \# & \% \\
\hline
 UNUSUAL\_XY & 19 & 0.09 & 70 & 0.18 & 70 & 0.18 \\
\hline
\end{tabular}
\end{table}

enter image description here

curious
  • 193

1 Answers1

1

In the following MWE, I used \widthof from the calc package in order to measure the width of the entry in the \multicolumn command. I then used 6 wc type columns from the array package instead of the regular c type columns. I then made sure, to use half of the before determined width as the width argument of the wc column.

enter image description here

The table in the following MWE exceeds the textwidth. I decided to not address that issue, since there was no documentclass given in the original question and I just guessed one.

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

\usepackage{array} % for the w column type \usepackage{calc} % for the \widthof command

\newlength{\mycolwidth} \setlength{\mycolwidth}{\widthof{CoreExome-24 v1.0}} \begin{document}

\begin{table} \centering \rowcolors{1}{}{lightgray} \begin{tabular}{|l|*{6}{wc{0.5\mycolwidth-2\tabcolsep}|}} \hline \multicolumn{7}{|c|}{Sample QC} \ \hline \multicolumn{1}{|c|}{} & \multicolumn{2}{c|}{CoreExome-24 v1.0} & \multicolumn{2}{c|}{CoreExome-24 v1.0} & \multicolumn{2}{c|}{CoreExome-24 v1.1}\ \cline{2-7} \multicolumn{1}{|c|}{QC Flag} & # & % & # & % & # & % \ \hline UNUSUAL_XY & 19 & 0.09 & 70 & 0.18 & 70 & 0.18 \ \hline \end{tabular} \end{table}

\end{document}

leandriis
  • 62,593
  • \documentclass{article}, apologies first question here. Thank you for the help – curious May 19 '21 at 13:34
  • If you want to make sure, your table fits into the textwidth of a regular article class document, add \small \setlength{\tabcolsep}{5pt} right after \centering. This will slightly reduce the font size as well as teh horizontal white space between an vertical line and the text in a table cell and thus allow the table to fit. With this approach you should get rid of the overfull box warning, that you get from the original code in my answer. – leandriis May 19 '21 at 13:57