长表中的多列超出范围,而其余列则没有

长表中的多列超出范围,而其余列则没有

我有以下工作正常的长表:

\documentclass[fontsize=11pt,paper=a4]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{longtable, tabu}

\begin{document}
\begin{longtable}[c]{|l|l|p{8.5cm}|}
\caption{Caption: Lorem ipsum}
\label{use-case_1}\\
\hline
\textbf{Use Case \#1}          & \multicolumn{2}{l|}{Lorem ipsum} \\ \hline
\endfirsthead
%
\endhead
%
\textbf{Goal in Context}       & \multicolumn{2}{l|}{Lorem ipsum.} \\ \hline
\textbf{Scope \& Level}        & \multicolumn{2}{l|}{Lorem ipsum.} \\ \hline
\textbf{Requirements Met}      & \multicolumn{2}{l|}{Lorem ipsum} \\ \hline
\textbf{Preconditions}         & \multicolumn{2}{l|}{TLorem ipsum dolor sit amet} \\ \hline
\textbf{Success End Condition} & \multicolumn{2}{l|}{Lorem ipsum dolor sit amet} \\ \hline
\textbf{Failed End Condition}  & \multicolumn{2}{l|}{Lorem ipsum dolor sit amet} \\ \hline
\textbf{Primary Actor}         & \multicolumn{2}{l|}{Lorem ipsum dolor sit amet} \\ \hline
\textbf{Description}           & \textbf{Step} & \textbf{Action} \\ \hline
                               & 1             & Lorem ipsum dolor sit amet. \\ \hline
                               & 2             & TLorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque et augue finibus massa imperdiet interdum id at massa. \\ \hline
\textbf{Extensions}            & \textbf{Step} & \textbf{Branching Action} \\ \hline
                               &             & TLorem ipsum dolor sit amet, \\ \hline
                               &               & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque et augue finibus massa imperdiet interdum id at massa. \\ \hline
\textbf{Sub-Variations}        & \textbf{Step} & \textbf{Branching Action} \\ \hline
                               & N/A           & N/A \\ \hline
\end{longtable}
\end{document}

上述代码生成的表格

但是,如果前八行(有多列)中的某一行的文本太长,它就会超出范围,而不是像表格末尾的其余列那样进行软换行,如下所示:

桌子超出范围或超出范围

我该怎么做才能解决这个问题?提前致谢

答案1

像这样?

在此处输入图片描述

(红线表示文本边框)

正如@DavidCarlisle 在他的评论中指出的那样,您应该使用p{...}列说明符而不是l,如下所示:

\documentclass[fontsize=11pt,paper=a4]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage{float}
\usepackage{array, longtable}
\usepackage{lipsum}

\begin{longtable}{|>{\bfseries}l|>{\centering\arraybackslash}p{9mm}|p{8cm}|}
\caption{Caption: Lorem ipsum}
\label{use-case_1}\\
    \hline
Use Case \#1    & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{Lorem ipsum} \\ \hline
%
Goal in Context & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{Lorem ipsum.} \\ \hline
Scope \& Level         & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{Lorem ipsum.} \\ \hline
Requirements Met       & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{Lorem ipsum} \\ \hline
Preconditions          & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{\lipsum[66]} \\ \hline
Success End Condition  & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{Lorem ipsum dolor sit amet} \\ \hline
Failed End Condition   & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{Lorem ipsum dolor sit amet} \\ \hline
Primary Actor          & \multicolumn{2}{p{\dimexpr8.9cm+2\tabcolsep}|}{Lorem ipsum dolor sit amet} \\ \hline
Description            & \textbf{Step} & \textbf{Action} \\ \hline
                               & 1             & Lorem ipsum dolor sit amet. \\ \hline
                               & 2             & TLorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque et augue finibus massa imperdiet interdum id at massa. \\ \hline
Extensions             & \textbf{Step} & \textbf{Branching Action} \\ \hline
                               &             & TLorem ipsum dolor sit amet, \\ \hline
                               &               & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque et augue finibus massa imperdiet interdum id at massa. \\ \hline
Sub-Variations         & \textbf{Step} & \textbf{Branching Action} \\ \hline
                               & N/A           & N/A \\ \hline
\end{longtable}
\end{document}

编辑:后两列的宽度已减小。现在表格不再太宽。

相关内容