用多行文本长表换行

用多行文本长表换行

我有以下想要复制的表格:

在此处输入图片描述

到目前为止,我的最佳尝试如下:

在此处输入图片描述

表格超出了页边距,我一直尝试手动调整单元格的宽度和高度以使其适合。

有没有一种方法可以使单元格在多行上自动调整,就像其余单元格一样?

我的 MWE 如下:

  \documentclass[a4paper,12pt,twoside,openany]{book}
  \usepackage{xltabular}
  \usepackage{float}
  \usepackage{tabu}

 \begin{document}
 \begin{longtable}{@{}| l | c | *{5}{c|} @{}}
 \hline
 \textbf{Set} & \textbf{Condition} & \textbf{Load [N]} & \textbf{Max. Speed 
 [mm/s]} & \textbf{Trapezoidal Motion Profil}\\ \hline
 \endfirsthead
 \multicolumn{5}{c}{\textbf{\tablename\ \thetable, continued from previous page}} 
 \\ \hline
 \textbf{Set} & \textbf{Condition} & \textbf{Load [N]} & \textbf{Max. Speed 
 [mm/s]} & \textbf{Trapezoidal Motion Profil}\\ \hline
 \endhead
 \multicolumn{5}{r@{}}{Continued on next page} \\ 
 \endfoot
 \endlastfoot
 \hline
1 & \multirow{5}{*}{Fault-free} & -44 & 40 & \multirow{2}{*}{40 mm, 1 s (10 
+ 10 seconds hold)} \\ \cline{1-1} \cline{3-4}
2 &   & 0 & 40 &    \\ \cline{1-1} \cline{3-5}
3 & & 0 & 80 & \multirow{2}{*}{40 mm, 21 s (0.5 + 0.5 seconds motion, 10 + 10 seconds hold)} \\ \cline{1-1} \cline{3-4}
4 &  & 44 & 80 &  \\ \cline{1-1} \cline{3-5}
5 & & 0 & 40 & 80 mm, 24 s (2+2 seconds motion, 10 + 10 seconds hold)  \\ \hline
6 & \multirow{5}{2cm}{Partial jam in screw return channel} &  -44 & 40 & 
\multirow{2}{3cm}{40 mm, 22 s (1+1 seconds motion, 10 + 10 seconds hold)} \\ 
[60pt] \cline{1-1} \cline{3-4}
7 &  & 0 & 40 &  \\  \cline{1-1} \cline{3-5}
8 &  & 0 & 80 & \multirow{2}{4cm}{40 mm, 21 s (0.5 + 0.5 seconds motion, 10+10 
seconds hold)}  \\[60pt] \cline{1-1} \cline{3-4}
9 &  & 44 & 80 &  \\ \cline{1-1} \cline{3-5}
10 &  & 0 & 40 & 80 mm, 24 s (2 + 2 seconds motion, 10 + 10 seconds hold) \\ 
\hline
\end{longtable}

\end{document}

有人可以帮帮我吗?

答案1

不错的小变化伯纳德答案。略有不同之处是:

  • 使用siunitx带单位的值包
  • 第二列的类型不同
  • 最后一列单元格内容的格式不同
  • 用于\caption表格标题

    \documentclass[a4paper,12pt,twoside,openany]{book}
     \usepackage[showframe]{geometry}
    \usepackage{makecell, multirow, ltablex}
    \renewcommand{\theadfont}{\small\bfseries}
    \usepackage{siunitx}
    \renewcommand\tabularxcolumn[1]{m{#1}}
    
     \begin{document}
    
    \begingroup
    \renewcommand\arraystretch{1.1}
    \begin{tabularx}{\linewidth}{@{}
                                |c|
                  >{\raggedright}m{25mm}
                                |S[table-format=-2.0]|
                                 S[table-format= 2.0]|
                                 X|
                                @{}}
    \caption{my table}
    \label{tab:longtable}                                   \\
        \Xhline{1pt}
    \thead{Set}
        &   \thead{Condition}
            &   {\thead{Load\\ {[N]}}}
                &   {\thead{Max.\\ Speed\\ {[mm/s]}}}
                    &   \thead{Trapezoidal Motion Profil}   \\
        \Xhline{0.5pt}
    \endfirsthead
    \caption{my table (cont.)}                     \\
        \Xhline{0.6pt}
    \thead{Set}
        &   \thead{Condition}
            &   {\thead{Load\\ {[N]}}}
                &   {\thead{Max.\\ Speed\\ {[mm/s]}}}
                    &   \thead{Trapezoidal Motion Profil}   \\
        \Xhline{0.3pt}
    \endhead
    \multicolumn{5}{r@{}}{\textit{Continued on next page}}  \\
    \endfoot
        \Xhline{0.6pt}
    \endlastfoot
    1 & \multirow{6}{=}{Fault-free}
            & -44   & 40 & \multirow{2.2}{=}{\SI{40}{mm}, \SI{21}{s}\newline
                           (\SI{0.5}{s} + \SI{0.5}{s} motion,
                            \SI{10}{s} + \SI{10}{s} hold)}  \\
        \cline{1-1}\cline{3-4}
    2 &     &   0   & 40 &                                  \\
        \cline{1-1}\cline{3-5}
    3 &     &   0   & 80 & \multirow{2.2}{=}{\SI{40}{mm}, \SI{21}{s}\newline
                           (\SI{0.5}{s} + \SI{0.5}{s} motion,
                            \SI{10}{s} + \SI{10}{s} hold)}  \\
        \cline{1-1}\cline{3-4}
    4   &   &  44   & 80 &                                  \\
        \cline{1-1}\cline{3-5}
    5   &   &   0   & 40 & \SI{80}{mm}, \SI{24}{s}\newline
                           (\SI{2}{s} + \SI{2}{s} motion,
                           \SI{10}{s} + \SI{10}{s} hold)   \\
        \hline
    6   & \multirow{6}{=}{Partial jam in screw return channel}
            & -44   & 40 & \multirow{2.2}{=}{\SI{40}{mm}, \SI{22}{s}\newline
                           (\SI{1}{s} + \SI{1}{s} motion,
                            \SI{10}{s} + \SI{10}{s} hold)}   \\
        \cline{1-1}\cline{3-4}
    7   &   &   0   & 40 &                                  \\
    \cline{1-1} \cline{3-5}
    8   &   &   0   & 80 & \multirow{2.2}{=}{\SI{40}{mm}, \SI{21}{s}\newline
                           (\SI{0.5}{s} + \SI{0.5}{s} motion,
                            \SI{10}{s} + \SI{10}{s} hold)}  \\
        \cline{1-1}\cline{3-4}
    9   &   &  44   & 80 &                                  \\
        \cline{1-1}\cline{3-5}
    10  &   &   0   & 40 & \SI{80}{mm}, \SI{24}{s}\newline
                           (\SI{2}{s} + \SI{2}{s} motion,
                           \SI{10}{s} + \SI{10}{s} hold)   \\
    \end{tabularx}
    \endgroup
    \end{document}
    

在此处输入图片描述

答案2

以下是使用和的解决方案\ltablexmakecellsiunitx

 \documentclass[a4paper,12pt,twoside,openany]{book}
 \usepackage[showframe]{geometry}
\usepackage{ltablex}
\usepackage{multirow, makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\usepackage{siunitx}
  \usepackage{float}
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}

 \begin{document}

\noindent
\sisetup{detect-weight}
\setlength{\extrarowheight}{3pt}
\setlength{\tabcolsep}{4pt}
\begin{tabularx}{\linewidth}{@{}!{\vrule width 1pt}c!{\vrule width 1pt}c |S[table-format=-2.0]| S[table-format=2.0]|X!{\vrule width 1pt}@{}}
 \Xhline{1pt}
 \thead{Set} & \thead{Condition} & {\thead{Load [N]}} & {\thead{Max.\\ Speed\\ {[\si{mm/s}]}}} & \thead{Trapezoidal Motion Profil}\\ \Xhline{0.8pt}
 \endfirsthead
 \multicolumn{5}{c}{\textbf{\tablename \thetable} {continued from previous page}}
 \\ \Xhline{1pt}
 \thead{Set} & \thead{Condition} & {\thead{Load [N]}} & {\thead{Max. \\Speed\\
 {[\si{mm/s}]}}} & \thead{Trapezoidal Motion Profil}\\ \Xhline{0.8pt}
 \endhead
 \multicolumn{5}{r@{}}{Continued on next page} \\
 \Xhline{0.8pt}
 \endfoot
 \Xhline{1pt}
 \endlastfoot
1 & \multirow{6}{*}{Fault-free} & -44 & 40 & \multirow{2}{=}{40 mm, 1 s (10
+ 10 seconds hold)} \\
\cline{1-1} \cline{3-4}
2 & & 0 & 40 & \\
 \cline{1-1} \cline{3-5}
3 & & 0 & 80 & \multirow{2}{=}{40 mm, 21 s (0.5 + 0.5 seconds motion, 10 + 10 seconds hold)} \\ \cline{1-1} \cline{3-4}
4 & & 44 & 80 & \\ \cline{1-1} \cline{3-5}
5 & & 0 & 40 & 80 mm, 24 s (2+2 seconds motion, 10 + 10 seconds hold) \\ \hline
6 & \multirow{6}{2.5cm}{Partial jam in screw return channel} & -44 & 40 &
 \multirow{2}{=}{40 mm, 22 s (1+1 seconds motion, 10 + 10 seconds hold)} \\
 \cline{1-1} \cline{3-4}
7 & & 0 & 40 & \\
\cline{1-1} \cline{3-5}
8 & & 0 & 80 & \multirow{2}{=}{40 mm, 21 s (0.5 + 0.5 seconds motion, 10+10
seconds hold)} \\
\cline{1-1} \cline{3-4}
9 & & 44 & 80 & \\
\cline{1-1} \cline{3-5}
10 & & 0 & 40 & 80 mm, 24 s (2 + 2 seconds motion, 10 + 10 seconds hold)
\end{tabularx}

\end{document} 

在此处输入图片描述

相关内容