如何自动将表格中的段落移到下一行?

如何自动将表格中的段落移到下一行?

如何自动将表格中的段落移至下一行?它会自动调整我的表格宽度

        \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{multirow}


    \title{For Testing}
    \author{TEST }
    \date{August 2022}

    \begin{document}

    \begin{tabular}{| c | L{3cm} | L{3cm} | R{5cm} |}
    \hline
        \multicolumn{1}{|c|}{\footnotesize{\textbf{\fontsize{7pt}{7pt}\fontfamily{phv}\selectfont No.}}} & 
        \multicolumn{1}{|c|}{\footnotesize{\textbf{\fontsize{7pt}{7pt}\fontfamily{phv}\selectfont In Charage}}} & 
        \multicolumn{1}{|c|}{\footnotesize{\textbf{\fontsize{7pt}{7pt}\fontfamily{phv}\selectfont Operation Description}}} & 
        \multicolumn{1}{|c|}{\footnotesize{\textbf{\fontsize{7pt}{7pt}\fontfamily{phv}\selectfont Remarks}}}\\
    \hline
    1 & \multirow[t]{2}{*}{XXXXXXXXXXXXXXXXXXXXXX} & Collumn 3 & Collumn 4 \\
    \cline{1-1} \cline{3-4}
    2 & & Collumn 3 & Collumn 4 \\
    \hline
    3 & Collumn 2 & Collumn 3 & Collumn 4 \\
    \hline
    4 &
    Collumn 2 &
    Collumn 3 &
    Collumn 4 \\
    \hline
    5 &
    Collumn 2 &
    Collumn 3 &
    Collumn 4 \\
    \hline
    6 &
    Collumn 2 &
    Collumn 3 &
    Collumn 4 \\
    \hline
    \end{tabular}\\

    \end{document}

在此处输入图片描述

答案1

你应该使用:

\multirow{2}{=}{XXXXXX XXXXXXX XXXXXXXXX}

(观察=

  • 您的表格代码有点奇怪。我建议使用makecell包及其宏\thead,您可以根据需要定义字体样式。通过它\multicolumn在表格代码中替换。例如,如以下 MWE 中所做的那样。
  • 表格比文本宽度宽。您需要相应地更改列宽。

编辑: 哎呀,我上传了错误版本的表格代码。现已更正。

\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{array, 
            makecell,
            multirow}
\renewcommand\theadfont{\footnotesize\bfseries}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}


    \title{For Testing}
    \author{TEST }
    \date{August 2022}

\begin{document}
\begin{center}
    \begin{tabular}{| c | L{4cm} | L{3cm} | R{2.8cm}|}
    \hline
\thead{No.} 
    & \thead{In Charage}    
                & \thead{Operation\\ Description} 
                                & \thead{Remarks}   \\
    \hline
 1  & \multirow{2}{=}{XXXXXX XXXXXXX XXXXXXXXX}
                & Collumn 3     & Collumn 4         \\
    \cline{1-1} \cline{3-4}
 2  &           & Collumn 3     & Collumn 4         \\
    \hline
 3 & Collumn 2  & Collumn 3     & Collumn 4         \\
    \hline
 4 & Collumn 2  & Collumn 3     & Collumn 4         \\
    \hline 
 5 & Collumn 2  & Collumn 3     & Collumn 4         \\
 6 & Collumn 2  & Collumn 3     & Collumn 4         \\
    \hline
    \end{tabular}
\end{center}
\end{document}

在此处输入图片描述

(红线表示页面溢出)

附录: 使用该tabularray包可以获得更佳的结果和更简单的表格代码。它的语法略有不同,包文档中对此进行了详细描述。

\documentclass{article}
\usepackage{tabularray}

    \title{For Testing}
    \author{TEST }
    \date{August 2022}

\begin{document}
\begin{center}
    \begin{tblr}{hlines, vlines,
                 colspec = {c X[l] X[l] X[r]},
                 row{1}  = {font=\footnotesize\bfseries, m},
                 vspan   = even
                 }
No. & In Charage    & Operation Description & Remarks       \\
 1  & \SetCell[r=2]{l}  XXXXXX XXXXXXX XXXXXXXXX
                    & Collumn 3             & Collumn 4     \\
 2  &               & Collumn 3             & Collumn 4     \\
 3 & Collumn 2      & Collumn 3             & Collumn 4     \\
 4 & Collumn 2      & Collumn 3             & Collumn 4     \\
 5 & Collumn 2      & Collumn 3             & Collumn 4     \\
 6 & Collumn 2      & Collumn 3             & Collumn 4     \\
    \end{tblr}
\end{center}
\end{document}

在此处输入图片描述

上例中最后三列宽度相等。但你只需改变列宽比例即可。例如:

colspec = {c X[0.8,l] X[0.8,l] X[1.4, r]},

在此处输入图片描述

相关内容