如何使用 \multicolumn 在 tabularx 中實作自動換行?

如何使用 \multicolumn 在 tabularx 中實作自動換行?

我正在使用tabularx,現在我想將一行的所有 3 個單元格合併為一個單元格,但我的文本很長,我不知道如何讓它在這種環境中的文本中自動換行。有人知道我該做什麼嗎?

\documentclass[10pt,a4paper,final,twoside]{book}
\usepackage{amsmath}

\usepackage{tabularx}
\usepackage{makecell}
\usepackage{multirow}

\usepackage{multicol}
\setlength{\columnsep}{1.5cm}
\setlength{\columnseprule}{0.2pt}

\usepackage{polyglossia}
\setmainlanguage{french}

  \begin{document}
  \begin{center}
    \begin{tabularx}{1.\linewidth}{|p{.31\linewidth} | p{.31\linewidth} |     p{.31\linewidth} |}
    \hline 
    \textbf{Ernout/Meillet\textsubscript{4}} & \textbf{REW\textsubscript{3}} & \textbf{DÉRom}  \\ 
    \hline 
    apert\={u}ra & ap\u{e}rt\={u}ra & \makecell[l]{*/aper\textquotesingle t-ur-a/\\\hspace{4pt} $\longrightarrow$ I. */aper\textquotesingle t-ur-a/  \\ \hspace{4pt} $\longrightarrow$ II. */oper\textquotesingle t-ur-a/} \\ 
    \hline
    \multicolumn{3}{|c|}{Les issues romanes ont été subdivisées selon les deux types dont elles relèvent : */aper't-ur-a/ (I.) et */oper't-ur-a/ (II.). I. représente une évolution phonétique régulière de protorom. */aper't-ur-a/ et il existe en italien, romanche, espagnol, asturien, galicien et portugais....  }   \\
    \hline 
    \end{tabularx} 
    \end{center}

在此輸入影像描述

答案1

最後一部分使用X列和列。p

\documentclass[10pt,a4paper,final,twoside]{book}
\usepackage{amsmath}

\usepackage{tabularx}
\usepackage{makecell}
\usepackage{polyglossia}

\setmainlanguage{french}

\begin{document}

\begin{center}

\begin{tabularx}{\linewidth}{|X|X|X|}
\hline 
\textbf{Ernout/Meillet\textsubscript{4}} & \textbf{REW\textsubscript{3}} & \textbf{DÉRom}  \\ 
\hline 
apert\={u}ra & ap\u{e}rt\={u}ra & 
  \makecell[l]{%
    */aper\textquotesingle t-ur-a/\\
    \hspace{4pt} $\longrightarrow$ I. */aper\textquotesingle t-ur-a/ \\
    \hspace{4pt} $\longrightarrow$ II. */oper\textquotesingle t-ur-a/
  } \\
\hline
\multicolumn{3}{|p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}|}{%
  Les issues romanes ont été subdivisées selon les deux types dont elles
  relèvent: */aper't-ur-a/ (I.) et */oper't-ur-a/ (II.). I. représente
  une évolution phonétique régulière de protorom. */aper't-ur-a/ et il
  existe en italien, romanche, espagnol, asturien, galicien et portugais....  } \\
\hline 
\end{tabularx} 
\end{center}

\end{document}

在此輸入影像描述

答案2

我建議的是一個清理解決方案。 IE:

  1. 刪除了桌子兩側的額外間距
  2. tabularx由於未使用 X 列而被刪除
  3. @{}m{\textwidth}@{}對於我實際使用的新專欄:

    A。擺脫@{}額外的間距

    b.給出\textwidth了所需的廣度(可調整以獲得最佳效果)

    C。規格m允許單元格連字符

  4. 去掉了所有的垂直分隔符,因為它們很醜而且會損害可讀性

  5. 使用這些booktabs規則是因為它們更奇特
  6. 刪除了多餘的水平線(最多可以考慮midrule長單元格之前的a

所以這是代碼

\documentclass[10pt,a4paper,final,twoside]{book}
\usepackage{amsmath}

\usepackage{tabularx, booktabs}
\usepackage{makecell}
\usepackage{multirow}

\usepackage{multicol}
\setlength{\columnsep}{1.5cm}
\setlength{\columnseprule}{0.2pt}

\usepackage{polyglossia}
\setmainlanguage{french}

  \begin{document}
  \begin{center}
    \begin{tabular}{@{}p{.31\linewidth} p{.31\linewidth}  p{.31\linewidth}@{}}
\toprule
    \textbf{Ernout/Meillet\textsubscript{4}} & \textbf{REW\textsubscript{3}} & \textbf{DÉRom}  \\ 
    \midrule 
    apert\={u}ra & ap\u{e}rt\={u}ra & \makecell[l]{*/aper\textquotesingle t-ur-a/\\\hspace{4pt} $\longrightarrow$ I. */aper\textquotesingle t-ur-a/  \\ \hspace{4pt} $\longrightarrow$ II. */oper\textquotesingle t-ur-a/} \\ 

    \multicolumn{3}{@{}m{\textwidth}@{}}{Les issues romanes ont été subdivisées selon les deux types dont elles relèvent : */aper't-ur-a/ (I.) et */oper't-ur-a/ (II.). I. représente une évolution phonétique régulière de protorom. */aper't-ur-a/ et il existe en italien, romanche, espagnol, asturien, galicien et portugais....  }   \\
    \bottomrule 
    \end{tabular} 
    \end{center}

    \end{document}

和一個樣品

在此輸入影像描述

答案3

用於p{\dimexpr0.93\linewidth+4\tabcolsep}寬度和。當然不tabularx

\documentclass[10pt,a4paper,final,twoside]{book}
\usepackage{amsmath}

\usepackage{tabularx}
\usepackage{makecell}
\usepackage{multirow}

\usepackage{multicol}
\setlength{\columnsep}{1.5cm}
\setlength{\columnseprule}{0.2pt}

\usepackage{polyglossia}
\setmainlanguage{french}

\begin{document}

\begin{center}
    \begin{tabular}{|*3{p{.31\linewidth} |}}\hline 
    \textbf{Ernout/Meillet\textsubscript{4}} & \textbf{REW\textsubscript{3}} & 
    \textbf{DÉRom}  \\ \hline 
            apert\={u}ra & ap\u{e}rt\={u}ra & \makecell[l]{*/aper\textquotesingle 
            t-ur-a/\\\hspace{4pt} $\longrightarrow$ I. */aper\textquotesingle t-ur-a/  \\ 
    \hspace{4pt} $\longrightarrow$ II. */oper\textquotesingle t-ur-a/} \\ \hline
\multicolumn{3}{|p{\dimexpr0.93\linewidth+4\tabcolsep}|}{Les issues romanes ont été 
subdivisées selon les deux 
types dont elles relèvent : */aper't-ur-a/ (I.) et */oper't-ur-a/ (II.). I. 
            représente une évolution phonétique régulière de protorom. */aper't-ur-a/ et 
            il existe en italien, romanche, espagnol, asturien, galicien et portugais....  
            }   \\\hline 
\end{tabular} 
\end{center}
\end{document}

在此輸入影像描述

有了tabularx它應該是:

\begin{tabularx}{\linewidth}{|X|X|X|}\hline 
... 
\multicolumn{3}{|p{\dimexpr\linewidth-2\tabcolsep}|}{...}
 ...
\end{tabularx}

相關內容