如何拆分表格单元格中的文本

如何拆分表格单元格中的文本

我需要拆分单元格中的文本。我尝试过,\par但此命令在括号内不起作用{ }。我的尝试如下。

enter image description here

\begin{table}[]
\centering
\caption{Caption}\label{tab2}
\begin{tabular}{|p{4cm}|p{4cm}|p{4cm}|}
\hline
\multicolumn{1}{|c|} {\textbf{Title1}} & \multicolumn{1}{c|} {\textbf{Title2}} & \multicolumn{1}{c|} {\textbf{Title3}} \\ \hline
\multicolumn{1}{|l|}{text text text text} & text text text  text  text & text text text text text text text text text text \\ \hline
\multicolumn{1}{|l|}{ text text text } & text text text text text & text text text text text text text text text text text text \\ \hline
\multicolumn{3}{|c|}{ text text text } \\ \hline
\multicolumn{1}{|l|}{ text text text } & связях text text text text & text \\ \hline
\multicolumn{3}{|c|}{ text text }   \\ \hline
\multicolumn{1}{|l|}{ text text text } & text text text & text text text \\ \hline
\multicolumn{3}{|c|}{ text } \\ \hline
\multicolumn{2}{|c|}{ text text text } & text \\ \hline
\multicolumn{3}{|c|}{ text …} \\ \hline
\multicolumn{1}{|l|} {text text  texttexttext \par texttexttext} & texttexttext \par texttexttext texttexttexttext & texttexttexttext texttexttexttext \\ \hline
\end{tabular}
\end{table}

答案1

你的\multicolumn{1}{l}尝试失败了。请参阅更正版本:

\documentclass{article}


\begin{document}

\begin{table}[]
\centering
\caption{Caption}\label{tab2}
\begin{tabular}{|p{4cm}|p{4cm}|p{4cm}|}
\hline
\multicolumn{1}{|c|} {\textbf{Title1}} & \multicolumn{1}{c|} {\textbf{Title2}} & \multicolumn{1}{c|} {\textbf{Title3}} \\ \hline
\multicolumn{1}{|l|}{text text text text} & text text text  text  text & text text text text text text text text text text \\ \hline
\multicolumn{1}{|l|}{ text text text } & text text text text text & text text text text text text text text text text text text \\ \hline
\multicolumn{3}{|c|}{ text text text } \\ \hline
\multicolumn{1}{|l|}{ text text text } & связях text text text text & text \\ \hline
\multicolumn{3}{|c|}{ text text }   \\ \hline
\multicolumn{1}{|l|}{ text text text } & text text text & text text text \\ \hline
\multicolumn{3}{|c|}{ text } \\ \hline
\multicolumn{2}{|c|}{ text text text } & text \\ \hline
\multicolumn{3}{|c|}{ text …} \\ \hline
%\multicolumn{1}{|l|} {text text  texttexttext \par texttexttext} & texttexttext \par texttexttext texttexttexttext & texttexttexttext texttexttexttext \\ \hline
{text text  texttexttext \par texttexttext} & texttexttext \par texttexttext texttexttexttext & texttexttexttext texttexttexttext \\ \hline
\end{tabular}
\end{table}

\end{document}

enter image description here

答案2

  • 您的表中所有\multicolumn{1}{...}{...}内容都是多余的。删除它们。
  • 对于列标题,使用\thead包中的宏makecell
  • 为了使表格看起来更美观,我将使用\setcellgapes{3pt}\makegapedcells包中的功能在单元格内容周围添加垂直空间makecell

    \documentclass{article}
    \usepackage{makecell}
    \renewcommand\thead{\normalsize\bfseries}
    \renewcommand\theadgape{}
    
    \begin{document}
        \begin{table}[htb]
        \setcellgapes{3pt}\makegapedcells
        \centering
    \caption{Caption}
        \label{tab2}
    \begin{tabular}{|p{4cm}|p{4cm}|p{4cm}|}
        \hline
    \thead{Title1}  & \thead{Title2}    & \thead{Title3}                    \\
        \hline
    text text text text
        & text text text text text
            & text text text text text text text text text text             \\
        \hline
    text text text
        & text text text text text
            & text text text text text text text text text text text text   \\
        \hline
    \multicolumn{3}{|c|}{ text text text }                                  \\
        \hline
    text text text
        & text text text text
            & text                                                          \\
        \hline
    \multicolumn{3}{|c|}{ text text }                                       \\
        \hline
    text text text
        & text text text
            & text text text                                                \\
        \hline
    \multicolumn{3}{|c|}{ text }                                            \\
        \hline
    \multicolumn{2}{|c|}{ text text text }
            & text                                                          \\
        \hline
    \multicolumn{3}{|c|}{ text \dots}                                       \\
        \hline
    text text  texttexttext \par
    texttexttext
        & texttexttext \par
          texttexttext texttexttexttext
            & texttexttexttext texttexttexttext                             \\
        \hline
    \end{tabular}
        \end{table}
    \end{document}
    

enter image description here

相关内容