2

I am new to LaTeX and I am trying to create a table. I have read all the documentation about tables from Wikibooks. The problem I am having is while using \cline my column spacing is uneven.

table with uneven column

I've have the following code:

    %begin table 1
\begin{table*}
\centering      
\caption{Description of datasets of proficiency test results from AAFCO check sample program}
\setlength{\abovecaptionskip}{10pt}
\setlength{\belowcaptionskip}{-12pt}
\setlength\extrarowheight{4pt} % sets row height
\setlength{\tabcolsep}{15pt} % sets column space
%\renewcommand{\arraystretch}{1}
\vspace{6pt}

\scalebox{1.0}{ \begin{tabular}{ | c | c | c | c | c | }

\hline

\multirow{2}{}{Year} & \multirow{2}{}{Feed Type} & \multicolumn{2}{ c| }{# of laboratories submitting the PT results} & \multirow{2}{*}{# of analyses} \ \cline{3-4}

& & Min & Max & \ \hline

test & test & test & test & test \ \hline

\end{tabular} \label{tab:tab1} } \end{table*} %end table 1

one remedy that I have tried is using \multirow{1}{2.5cm}{Min}, but my text is not aligned. Picture is below

remedy

I am trying to recreate this table. Any help would be much appreciated. Thanks.

desired table

jay0987
  • 23
  • 4

2 Answers2

3

A solution with the wc column type. I removed the \scalebox command, which shouldn't be used with tables, as it leads to inconsistent font sizes.

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{array, multirow}
    \usepackage{makecell}
\begin{document}

\begin{table*}
\centering
\caption{Description of datasets of proficiency test results from AAFCO check sample program}

    \setlength{\abovecaptionskip}{10pt}
    \setlength{\belowcaptionskip}{-12pt}
    \setlength\extrarowheight{4pt} % sets row height
    \setlength{\tabcolsep}{15pt} % sets column space
    \vspace{6pt}
\begin{tabular}{ | c | c | wc{15mm} | wc{15mm} | c | }
\hline
\multirow{2}{*}{Year} & \multirow{2}{*}{Feed Type} & \multicolumn{2}{ c| }{\makecell{\# of laboratories\\
submitting the PT results}} & \multirow{2}{*}{\# of analyses} \\ \cline{3-4}
 & & Min & Max & \\
\hline
test & test & test & test & test \\
\hline
\end{tabular}
\label{tab:tab1}
\end{table*}

\end{document} 

enter image description here

Sebastiano
  • 54,118
Bernard
  • 271,350
  • 1
    Thanks for the edit, @Sebastiano ! : o) – Bernard Mar 23 '22 at 19:37
  • Ahahahah :-) you're welcome. It is always a pleasure to help the other users. – Sebastiano Mar 23 '22 at 19:40
  • so the wc column type sets a determined word limit, and the \makecell command is for putting contents within that cell @Bernard? – jay0987 Mar 24 '22 at 16:21
  • @jay0987: The wc column type is a recent column type, somewhet like p, but adds that the contents is centred; makecell allows for line breaks in all types of cells, and its contents is centred by default, both vertically and horizontally. – Bernard Mar 24 '22 at 16:29
  • @Bernard: I did not know that. I haven't seen that yet. I have only seen the column types p, m, and b for alignment. Thank you for your time and speedy reply! – jay0987 Mar 24 '22 at 16:37
  • @jay0987: This is explained (I mean wc and similar) in the documentation of recent versions of the array package. – Bernard Mar 24 '22 at 16:43
1

Here's a solution which (a) uses a tabularx enviroment and allows automatic line-breaking (with hanging indentation) in the second column and (b) uses fixed equal widths for columns 3, 4, and 5. It also does away with all vertical lines and uses few, but well-spaced horizontal lines.

enter image description here

\documentclass{article}
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{array}    % for 'w' and 'm' column types
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1em}X}
\usepackage{calc}
\usepackage[skip=0.5\baselineskip]{caption}

\begin{document}

\begin{table*}
\caption{Description of datasets of proficiency test results from AAFCO check sample program} \label{tab:tab1} \newlength\mylen \settowidth\mylen{# of analyses} % measure widths of cols 2 thru 5

\begin{tabularx}{\textwidth}{@{} l L {3}{wc{\mylen}} @{}} \toprule Year & Feed Type & \multicolumn{2}{ >{\centering}m{2\mylen+2\tabcolsep} }{% # of laboratories submitting the PT results} & # of analyses \ \cmidrule(lr){3-4} & & min & max & \ \midrule 2022 & Beet pulp & 5 & 55 & 45 \ & Calf starter\slash grower, medicated & 6 & 209 & 58 \ & \dots \ & Ewe developer & gestation feed, medicated & 10 & 214 & 35 \ & \dots \ & Pelleted sheep concentrate, medicated & 7 & 212 & 54 \ & \dots \ & Swine grower, medicated & 5 & 155 & 55 \ \bottomrule \end{tabularx} \end{table}

\end{document}

Mico
  • 506,678