[Tex/LaTex] Table rowspan and colspan

horizontal alignmentmulticolumnmultirowtablesvertical alignment

I need to create similar table using LaTeX:

table

I have tried to use \tabular and \multicolumn, but every time I get something wrong.

I want:

  • Fixed width columns and fixed height rows;
  • Centered cells (vertically and horizontally)
  • Borders around each cell

Could someone help me?

Here is pure HTML markup:

<table border="1" cellpadding="0" cellspacing="0">
    <tr height="50">
        <td align="center" width="150" rowspan="2">State of Health</td>
        <td align="center" width="300" colspan="2">Fasting Value</td>
        <td align="center" width="150">After Eating</td>
    </tr>
    <tr height="50">
        <td align="center" width="150">Minimum</td>
        <td align="center" width="150">Maximum</td>
        <td align="center" width="150">2 hours after eating</td>
    </tr>
    <tr height="50">
        <td align="center" width="150">Healthy</td>
        <td align="center" width="150">70</td>
        <td align="center" width="150">100</td>
        <td align="center" width="150">Less than 140</td>
    </tr>
    <tr height="50">
        <td align="center" width="150">Pre-Diabetes</td>
        <td align="center" width="150">101</td>
        <td align="center" width="150">126</td>
        <td align="center" width="150">140 to 200</td>
    </tr>
    <tr height="50">
        <td align="center" width="150">Diabetes</td>
        <td align="center" width="150">More than 126</td>
        <td align="center" width="150">N/A</td>
        <td align="center" width="150">More than 200</td>
    </tr>
</table>

Best Answer

You could use the multirow package to organize the cell in the north-west corner of the table, and the tabularx package to automatically generate four columns of equal width. In the MWE below, the \newcolumntype instruction sets up a new column type, called "Y", that centers its contents. Adjust the value of the \arraystretch macro to get the amount of vertical stretching to your liking.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{2}
\begin{document}\pagestyle{empty}
\begin{tabularx}{\textwidth}{|*{4}{Y|}}
\hline
\multirow{2}{*}{State of Health} 
  &\multicolumn{2}{c|}{Fasting Value}&After Eating\\
\cline{2-4}
             &Minimum       &Maximum &2 hours after eating\\
\hline
Healthy      &70            &100     &Less than 140\\
\hline
Pre-Diabetes &101           &126     &140 to 200\\
\hline
Diabetes     &More than 126 &N/A     &More than 200\\
\hline
\end{tabularx}
\end{document}
Related Question