I want to create a table in this format, but I haven't managed to get it to work.
I dont need to have any colour, i would just like to have it shown as a plain table.
Tables – Table with Multiple Columns
tables
Related Solutions
You could achieve the double line by using \hhline{#=#===#=#}
as in
But if you zoom out you'll see some weird details as the one inside the red circle (but visible along the lines):
But as you would read somewhere else, I'd advise against the use of vertical rules to improve readability. Not to mention that you would have a much cleaner code.
So this is my suggestion for your table. It uses the booktabs
package which makes for much better lines:
And the code:
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{booktabs}
\pagestyle{empty}
\begin{document}
\begin{tabular}{ccccc}
\toprule
\multirow{2}{*}{n} & \multicolumn{3}{c}{p} & \multirow{2}{*}{k} \\ \cmidrule{2-4}
& .1 & .25 & .5 & \\ \midrule
& \ldots & \ldots & \ldots & 1 \\ \cmidrule{2-4}
3 & \ldots & \ldots & \ldots & 2 \\ \cmidrule{2-4}
& \ldots & \ldots & \ldots & 3 \\ \midrule
& \ldots & \ldots & \ldots & 1 \\ \cmidrule{2-4}
4 & \ldots & \ldots & \ldots & 2 \\ \cmidrule{2-4}
& \ldots & \ldots & \ldots & 3 \\ \midrule
& \ldots & \ldots & \ldots & 1 \\ \cmidrule{2-4}
5 & \ldots & \ldots & \ldots & 2 \\ \cmidrule{2-4}
& \ldots & \ldots & \ldots & 3 \\ \bottomrule
\end{tabular}
\end{document}
Assuming you want to stay with the tabularx
table type that was used in my answer to the posting Table rowspan and colspan, you may achieve your objective using the methods set forth in section 4.3 of the user guide of the tabularx
package. The method described there works by adjusting the relative widths of the columns of type X
. (Naturally, if your tabularx
table contains only a single column of type X
, its width is fully determined as a residual, viz., as the difference between the overall text width and the sum of the widths of the other columns and intercolumn spaces.)
The following example shows how to this may be done to create a table in which the first and fourth columns are 50% wider than the two middle columns. Note how the four \hsize
values -- 1.2, 0.8, 0.8, and 1.2 -- sum to 4, which is the number of columns of type X
(or, to be even more precise, Y
, where Y
is a modified form of X
).
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{2}
\begin{document}
\emph{Original form: All columns are equally wide.}
\noindent
\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}
\bigskip
\emph{Modified form: Columns 1 and 4 are 50\% wider than columns 2 and 3.}
\smallskip\noindent
\begin{tabularx}{\textwidth}{|
>{\hsize=1.2\hsize}Y|
>{\hsize=0.8\hsize}Y|
>{\hsize=0.8\hsize}Y|
>{\hsize=1.2\hsize}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}
Best Answer
You're right about not wanting colors; however, you don't want vertical rules either. Nor it's necessary that “Data set” is lowered: the first row has the column headers, some of which have subheaders in the second row, with a horizontal rule to show the groups.
With
siunitx
and itsS
column you can get exact spacing between columns, alignment under the decimal point and automatic management of numbers (see in the eighth column).The input is straightforward; only some care is needed for adjusting the column specifiers, which can be done when the data are in their final form.
A local setting of
\tabcolsep
is necessary, at least for the standard text width; if you have a different text width you may be able to omit the setting or you may need to change the size.