Difficulty in using multicolumn or multirow in tabularx

I just started learning latex and needed a kind of table like what the uploaded picture shows. The code was generated by Excel2LaTex. I have tried some ways but cannot make it.

Several cells in the lower left corner of the table are merged. The command \tabular cannot make the table adaptively adjust the width to the whole row. If I use \resizebox, the height of the table will increase together, which will be very unsightly. So I used \tabularx but it always went wrong...Although I knew that \tabular cannot be simply replaced by \tabularx, I had no idea dealing with it...

So I come here for help. By the way, if it is really difficult, the big fork in the big cell can not be used. After all, this is drawn by Excel and it is very simple there.

\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
order & number & weight & order & number & weight \\
\hline
1     & 1     & 1     & 1     & 1     & 1 \\
\hline
2     & 2     & 2     & 2     & 2     & 2 \\
\hline
3     & 3     & 3     & 3     & 3     & 3 \\
\hline
...   & ...   & ...   & ...   & ...   & ... \\
\hline
118   & 118   & 118   & 118   & 118   & 118 \\
\hline
119   & 119   & 119   & 119   & 119   & 119 \\
\hline
120   & 120   & 120   & 120   & 120   & 120 \\
\hline
\multicolumn{3}{|c|}{\multirow{4}[8]{*}{}} & ...   & ...   & ... \\
\cline{4-6}    \multicolumn{3}{|c|}{}      & 138   & 138   & 138 \\
\cline{4-6}    \multicolumn{3}{|c|}{}      & 139   & 139   & 139 \\
\cline{4-6}    \multicolumn{3}{|c|}{}      & 140   & 140   & 140 \\
\hline
\end{tabular}%
\end{table}%


I also tried tablesgenerator website. It gave me the following code:

% Please add the following required packages to your document preamble:
% \usepackage{multirow}
\begin{table}[]
\caption{}
\label{tab:my-table}
\begin{tabular}{|ccc|c|c|c|}
\hline
\multicolumn{1}{|c|}{order} & \multicolumn{1}{c|}{number} & weight & order & number & weight \\ \hline
\multicolumn{1}{|c|}{1}     & \multicolumn{1}{c|}{1}      & 1      & 1     & 1      & 1      \\ \hline
\multicolumn{1}{|c|}{2}     & \multicolumn{1}{c|}{2}      & 2      & 2     & 2      & 2      \\ \hline
\multicolumn{1}{|c|}{3}     & \multicolumn{1}{c|}{3}      & 3      & 3     & 3      & 3      \\ \hline
\multicolumn{1}{|c|}{...}   & \multicolumn{1}{c|}{...}    & ...    & ...   & ...    & ...    \\ \hline
\multicolumn{1}{|c|}{118}   & \multicolumn{1}{c|}{118}    & 118    & 118   & 118    & 118    \\ \hline
\multicolumn{1}{|c|}{119}   & \multicolumn{1}{c|}{119}    & 119    & 119   & 119    & 119    \\ \hline
\multicolumn{1}{|c|}{120}   & \multicolumn{1}{c|}{120}    & 120    & 120   & 120    & 120    \\ \hline
\multicolumn{3}{|c|}{\multirow{4}{*}{}}                            & ...   & ...    & ...    \\ \cline{4-6}
\multicolumn{3}{|c|}{}                                             & 138   & 138    & 138    \\ \cline{4-6}
\multicolumn{3}{|c|}{}                                             & 139   & 139    & 139    \\ \cline{4-6}
\multicolumn{3}{|c|}{}                                             & 140   & 140    & 140    \\ \hline
\end{tabular}
\end{table}


@Mico: I didn't know how to insert a lot of code into the comments, so I answered my own question here. It's just an information table and I want it to look better. The following code has integrated Mico's code.

\documentclass{article}
\usepackage[english]{babel}
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{gensymb}
\usepackage{multirow,tabularx,ragged2e,booktabs,longtable}
\newcolumntype{C}{>{\Centering}X} % centered version of X col. type
\usepackage[skip=0.333\baselineskip]{caption}

\begin{document}

\begin{table}[htbp]
\caption{Fast Hankel Transform} \label{FHT}
\begin{tabularx}{\linewidth}{|*{6}{C|}}
\hline
Order     & Abscissa of $J_0$    & Weight of $J_0$       & Order      & Abscissa of $J_1$    & Weight of $J_1$         \\\hline
1         & $-19.32$             & $9.63\times10^{-7}$   & 1          & $-18.21$             & $-6.77\times10^{-14}$   \\\hline
2         & $-19.11$             & $-5.02\times10^{-6}$  & 2          & $-18.01$             & $3.40\times10^{-13}$    \\\hline
3         & $-18.90$             & $1.25\times10^{-5}$   & 3          & $-17.81$             & $-7.43\times10^{-13}$   \\\hline
$\vdots$  & $\vdots$             & $\vdots$              & $\vdots$   & $\vdots$             & $\vdots$                \\\hline
118       & $5.04$               & $6.23\times10^{-6}$   & 118        & $5.49$               & $7.33\times10^{-6}$     \\\hline
119       & $5.25$               & $-1.12\times10^{-6}$  & 119        & $5.69$               & $-3.76\times10^{-6}$    \\\hline
120       & $5.46$               & $1.04\times10^{-7}$   & 120        & $5.89$               & $1.86\times10^{-6}$     \\\hline
\multicolumn{3}{|c|}             {\multirow{4}{*}{}}     & $\vdots$   & $\vdots$             & $\vdots$                \\
\cline{4-6}    \multicolumn{3}{|c|}{}                    & 138        & $9.54$               & $-1.36\times10^{-9}$    \\
\cline{4-6}    \multicolumn{3}{|c|}{}                    & 139        & $9.74$               & $3.53\times10^{-10}$    \\
\cline{4-6}    \multicolumn{3}{|c|}{}                    & 140        & $9.94$               & $-4.54\times10^{-11}$   \\ \hline
\end{tabularx}
\end{table}
\end{document}

• Welcome to Tex.SX! So where is your problem: provided codes compile fine? If you really want to use diagonals in the huge cell, maybe you can try to use a TiKz matrix. BTW, I suggest to have a look at this question (and its answers!) in order to make nicer table than with excel
– NBur
Mar 17 at 8:36

Here are two possible solutions. Both take up the full width of the textblock. The first uses a tabularx environments (with centered versions of the Xcolumn type), and the second uses a tabular*-inspired longtable environment.

The two major differences between the tables is that second (a) gets rid of all vertical lines and most horizontal lines in order to give the table a more open and inviting "look" and (b) allows page breaks, as needed, which may be useful since the real table may have as many as 140 rows.

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs,longtable}
\newcolumntype{C}{>{\Centering}X} % centered version of 'X' col. type
\usepackage[skip=0.333\baselineskip]{caption}

\begin{document}

\begin{table}[htbp]
\caption{A prison window''-look table} \label{tab:addlabel1}
\begin{tabularx}{\textwidth}{|*{6}{C|}}
\hline
order & number & weight & order & number & weight \\
\hline
1     & 1     & 1     & 1     & 1     & 1 \\
\hline
2     & 2     & 2     & 2     & 2     & 2 \\
\hline
3     & 3     & 3     & 3     & 3     & 3 \\
\hline
\dots & \dots & \dots & \dots & \dots & \dots \\
\hline
118   & 118   & 118   & 118   & 118   & 118 \\
\hline
119   & 119   & 119   & 119   & 119   & 119 \\
\hline
120   & 120   & 120   & 120   & 120   & 120 \\
\hline
&&& \dots & \dots & \dots \\ \cline{4-6}
&&& 138   & 138   & 138   \\ \cline{4-6}
&&& 139   & 139   & 139   \\ \cline{4-6}
&&& 140   & 140   & 140   \\
\hline
\end{tabularx}
\end{table}

\begingroup % localize scope of next 4 instructions
\setlength\tabcolsep{0pt}
\setlength\LTcapwidth{\textwidth}
\setlength\LTleft{0pt}   % see p. 7 of user guide of longtable package
\setlength\LTright{0pt}
\begin{longtable}{@{\extracolsep{\fill}} *{6}{c} }

\caption{A table with a much more open look''} \label{tab:addlabel2}\\
\toprule
order & number & weight & order & number & weight \\
\midrule

\multicolumn{6}{l}{\tablename\ \thetable, cont'd}\\
\toprule
order & number & weight & order & number & weight \\
\midrule

\midrule
\multicolumn{6}{r@{}}{\footnotesize \em cont'd on following page}\\
\endfoot

\bottomrule
\endlastfoot

%% body of longtable

1     & 1     & 1     & 1     & 1     & 1 \\
2     & 2     & 2     & 2     & 2     & 2 \\
3     & 3     & 3     & 3     & 3     & 3 \\
$\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ \\
118   & 118   & 118   & 118   & 118   & 118 \\
119   & 119   & 119   & 119   & 119   & 119 \\
120   & 120   & 120   & 120   & 120   & 120 \\
&&& $\vdots$ & $\vdots$ & $\vdots$ \\
&&& 138   & 138   & 138 \\
&&& 139   & 139   & 139 \\
&&& 140   & 140   & 140 \\

\end{longtable}
\endgroup

\end{document}


Addendum to incorporate additional information provided by the OP: Here's a variant of the tabularx-based solution which (a) allows columns 1 and 4 to be narrower than columns 2, 3, 5, and 6 and (b) allows the numbers in the latter four columns to be aligned on their decimal markers, with the help of the S column type provided by the siunitx package.

\documentclass{article}
\usepackage[english]{babel}
\usepackage[letterpaper,vmargin=2cm,hmargin=3cm,
marginparwidth=1.75cm]{geometry}
\usepackage{amsmath,graphicx,gensymb}

\usepackage{tabularx,ragged2e}
\newcolumntype{C}{>{\Centering}X} % centered version of X col. type
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage{siunitx}
\newcommand\mC[1]{\multicolumn{1}{C|}{#1}} % handy shortcut macro

\begin{document}

\begin{table}[htbp]
\setlength\extrarowheight{2pt} % for a slightly more open "look"
\caption{Fast Hankel Transform} \label{FHT}
\begin{tabularx}{\linewidth}{| *{2}{ c | S[table-format=-2.2] |S[table-format=-1.2e-2]| } }
\hline
Order & \mC{Abscissa of $J_0$} & \mC{Weight of $J_0$} &
Order & \mC{Abscissa of $J_1$} & \mC{Weight of $J_1$} \\
\hline
1         & -19.32   &  9.63e-7  & 1          & -18.21     & -6.77e-14   \\ \hline
2         & -19.11   & -5.02e-6  & 2          & -18.01     &  3.40e-13   \\ \hline
3         & -18.90   &  1.25e-5  & 3          & -17.81     & -7.43e-13   \\ \hline
{$\vdots$} & {$\vdots$} & {$\vdots$} & {$\vdots$} & {$\vdots$} & {$\vdots$} \\ \hline
118       &   5.04   &  6.23e-6  & 118        &   5.49     &  7.33e-6    \\ \hline
119       &   5.25   & -1.12e-6  & 119        &   5.69     & -3.76e-6    \\ \hline
120       &   5.46   &  1.04e-7  & 120        &   5.89     &  1.86e-6    \\ \hline
\multicolumn{3}{|c|}{} & {$\vdots$} & {$\vdots$} & {$\vdots$} \\ \cline{4-6}
\multicolumn{3}{|c|}{} & 138        & 9.54       & -1.36e-9   \\ \cline{4-6}
\multicolumn{3}{|c|}{} & 139        & 9.74       &  3.53e-10  \\ \cline{4-6}
\multicolumn{3}{|c|}{} & 140        & 9.94       & -4.54e-11  \\ \hline
\end{tabularx}
\end{table}

\end{document}

• Thanks for your help. I tend to use the first one because the latter has a different style from my tables in article although it does look comfortable. But the first table will have a problem in my article, which is different from my other tables using \tabularx. That is, each horizontal line \hline will extend infinitely to the right of the paper, even if the rightmost content of the table is over. I don't know why my \textwidth is almost infinite. In contrast, my other tables do not have this problem probably because \multicolumn is not used. Mar 17 at 11:16
• @happyboat - I'm afraid I have idea how or why horizontal lines might "extend infinitely to the right". Please provide more information about what you're doing.
– Mico
Mar 17 at 11:25
• I studied my mistakes for some time. It turned out that I didn't notice the important code in the third line at the beginning, which made a little joke. And I have a further question. Now these six columns seem to be of equal width. In the actual table, the data recorded in each column of mine is not the same length, so I hope they can be unequal in width, but with no line breaks. How to modify such code? I don't know whether LaTeX can be intelligent enough, because it means that it can automatically allocate the width to each cell without manual adjustment, while ensuring no line breaks. Mar 17 at 12:02
• I don't know if you saw the code I pasted in my answer, but I've learned to share the code with you in the comments, which Diaa taught me. Code Link Mar 17 at 13:31
• I'm grateful to you for answering my question detailedly and patiently. I've learned a lot of useful things and successfully solved the difficulties. Thank you again and wish you all the best. Mar 18 at 3:29