我們可以同時使用 tabularx 和 multirow 嗎?

我們可以同時使用 tabularx 和 multirow 嗎?
\documentclass{article}
\usepackage{tabularx}
\usepackage{multirow}
\begin{document}

\begin{table}[h!]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
    \begin{tabularx}{\textwidth}{|c |c |c |X |X |X |}
    \hline
    1 & 2 & 3 & Testing 1 testing 2 Testing 3 & Testing 1 testing 2 Testing 3 & Testing 1 testing 2 Testing 3 \\
         \hline
    A & B & C & Test 1 & Test 1 & Test 1 \\
     &  &  & Test2  & Test2  & Test 2 \\
    \hline
    \end{tabularx}
\caption{tes}
\label{tab:my_label}
\end{table}

\begin{tabular}{|c|c|c|c|c|c|}
                                                                            \hline
   Text A                        &  Text B                       & Test C&  Testing 1 testing 2  3 &  1  2  3 & Testing 1  2  3\\\hline
   \multicolumn{2}{|c|}{\multirow{2}{*}{Longer Text, etc. etc.}} & Test F & Test R & Test O & test Y \\\cline{3-6}
   \multicolumn{2}{|c|}{}                                        & Test G & Test T & Test P & Test O \\\hline
\end{tabular}

\end{document}

輸出:

在此輸入影像描述

我想合併單元格,如下圖所示。

答案1

我將\hline其替換為\cline{1-6}並複製了其他一些文字。

新增了評論中建議的更改。

\documentclass{article}
\usepackage{tabularx}
\usepackage{multirow}
\begin{document}

\begin{table}[h!]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
    \begin{tabularx}{\textwidth}{|c |c |c |X |X |X |}
    \hline
    1 & 2 & 3 & Testing 1 testing 2 Testing 3 & Testing 1 testing 2 Testing 3 & Testing 1 testing 2 Testing 3 \\
         \hline
    A & B & C & Test 1 & Test 1 & Test 1 \\
     &  &  & Test2  & Test2  & Test 2 \\
    \hline
    \end{tabularx}
\caption{tes}
\label{tab:my_label}
\end{table}

\begin{table}[h!]
\setlength\extrarowheight{2pt} % for a ever so slightly more open "look"
\begin{tabularx}{\textwidth}{|X|X|c|c|c|c|}
   \cline{1-6}
   Text A                        &  Text B                       & Test C&  Testing 1 testing 2  3 &  1  2  3 & Testing 1  2  3\\
   \cline{1-6}
   \multicolumn{2}{|>{\hsize=2\hsize}X|}{\multirow{2}{=}{Longer Text, etc. etc.}} & Test F & Test R & Test O & Test Y \\
   \cline{3-6}
   \multicolumn{2}{|c|}{}                                        & Test G & Test T & Test P & Test O \\
   \cline{1-6}
\end{tabularx}
\caption{tabularx with multicolum and multirow}
\end{table}

\end{document}

具有多列和多行的 tabularx

相關內容