我一直在尝试构建一个特定大小的“复杂”表格,但间距方面仍然存在一些问题。如您在附图中看到的,一些线条与表格行分隔线重叠,其他线条则是随机的(我怀疑与多列表格中使用的 parbox 函数存在冲突)。有没有办法让间距更均匀、更美观?
\documentclass[]{article}
\usepackage{longtable}
\begin{document}
\begin{longtable}{| p{3.5cm} | p{2.5cm} | p{3.5cm} | p{2.5cm} |}
\caption{Use case detail}\label{chap3:tab1}\\
\multicolumn{4}{c}{}\\
\endfirsthead
\multicolumn{4}{c}{\tablename\ \thetable\ -- \textit{Continued from previous page}}\\
\multicolumn{4}{c}{}\\
\hline
\endhead
\hline \multicolumn{4}{r}{\tablename\ \thetable\ -- \textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case ID: & \multicolumn{3}{l|}{1}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case Name: & \multicolumn{3}{l|}{FIXME - Section Name}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Created by: & & Date created: &\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Actors & \multicolumn{3}{l|}{Doctor}\\
& \multicolumn{3}{l|}{Patient}\\
& \multicolumn{3}{l|}{Patients' Database}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Description: & \multicolumn{3}{l|}{\parbox{9cm}{The doctor logs into the system, creates/updates the patient medical record, prints the informed consent form and collects it after the patient has signed it.}}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Preconditions: & \multicolumn{3}{l|}{\parbox{9cm}{1. The doctor is logged into the web software.}}\\
& \multicolumn{3}{l|}{\parbox{9cm}{2. There is no record for the patient on the patients' database.}}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Postconditions: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Trigger: & \multicolumn{3}{l|}{\parbox{9cm}{The doctor logs in the system and presses the \textit{Login} button}}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Normal flow: & \multicolumn{3}{l|}{\parbox{9cm}{1. the doctor clicks on the \textit{Patients} icon;}}\\
& \multicolumn{3}{l|}{\parbox{9cm}{2. the doctor clicks on the \textit{Add} button;}}\\
& \multicolumn{3}{l|}{\parbox{9cm}{3. the doctor prints the consent form by clicking on the dedicated button;}}\\
& \multicolumn{3}{l|}{\parbox{9cm}{4. the doctor fills in the patient's details;}}\\
& \multicolumn{3}{l|}{\parbox{9cm}{5. the doctor collects the signed patient's consent form and ticks the dedicated check box;}}\\
& \multicolumn{3}{l|}{\parbox{9cm}{6. the doctor saves the patient's record by clicking the \textit{Save} button.}}\\
& \multicolumn{3}{l|}{\parbox{9cm}{}}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Alternative flows: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Exceptions: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Notes and issues: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
\end{longtable}
\end{document}
答案1
我认为您有太多的列和太多的标记,我认为我会这样做,除非您真的需要列表来分页。
\documentclass{article}
\usepackage{longtable,array}
\setlength\extrarowheight{3pt}
\begin{document}
\begin{longtable}{| p{3.5cm} | p{9cm} |}
\caption{Use case detail}\label{chap3:tab1}\\[12pt]
\endfirsthead
\multicolumn{2}{c}{\tablename\ \thetable\ -- \textit{Continued from previous page}}\\[12pt]
\hline
\endhead
\hline
\multicolumn{2}{r}{\tablename\ \thetable\ -- \textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case ID: & 1\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case Name: & FIXME - Section Name\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Created by:&\hspace{2cm}\vrule\ Date created:\hspace{2cm}\vrule\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Actors &
Doctor\newline
Patient\newline
Patients' Database\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Description: &
The doctor logs into the system, creates/updates the patient medical record, prints the informed consent form and collects it after the patient has signed it.\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Preconditions: &\mbox{}\par\vspace{-\baselineskip}
\begin{enumerate}
\item The doctor is logged into the web software.
\item There is no record for the patient on the patients' database.
\end{enumerate}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Postconditions: & \\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Trigger: & The doctor logs in the system and presses the \textit{Login} button\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Normal flow: &\mbox{}\par\vspace{-\baselineskip}
\begin{enumerate}
\item the doctor clicks on the \textit{Patients} icon;
\item the doctor clicks on the \textit{Add} button;
\item the doctor prints the consent form by clicking on the dedicated button;
\item the doctor fills in the patient's details;
\item the doctor collects the signed patient's consent form and ticks the dedicated check box;
\end{enumerate}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Alternative flows: & \\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Exceptions: & \\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Notes and issues: &\\
% --------------------------------------------------------------------------------------------------------------
\hline
\end{longtable}
\end{document}
答案2
不需要
\parbox
,列类型p
最好是垂直间距。宽度是根据默认p
列的三列宽度计算的。每列有两个\tabcolsep
,因此4\tabcolsep
为两个隐藏列添加 。\newlength\mymulticolwidth \setlength{\mymulticolwidth}{\dimexpr 2.5cm + 3.5cm + 2.5cm + 4\tabcolsep\relax}
该示例还添加了在行顶部添加
\extrarowheight
的包。array
枚举可以通过环境设置
enumerate
,其中对 Donald Arsenau 进行了一些改编,定义了一种新的列类型,如下所示丹尼尔·埃尔斯的回答。我只是设置了\leftmargini
去掉较大的缩进。如果数字超过 9,那么代码需要一些改进。
示例文件:
\documentclass{article}
\usepackage[
hmargin=15mm,
vmargin=15mm,
]{geometry}
\usepackage{longtable}
\usepackage{array}
\setlength{\extrarowheight}{2pt}
\newlength\mymulticolwidth
\makeatletter
\newcolumntype{e}[1]{%--- Enumerated cells ---
>{\minipage[t]{\linewidth}%
\NoHyper% Hyperref adds a vertical space because of anchor whatsit.
\let\\\tabularnewline
\settowidth{\leftmargini}{9.\hspace{\labelsep}}%
\enumerate
\addtolength{\rightskip}{0pt plus 50pt}% for raggedright
\setlength{\itemsep}{-\parsep}}%
p{#1}%
<{\@finalstrut\@arstrutbox\endenumerate
\endNoHyper
\endminipage}}
\AtBeginDocument{%
\@ifpackageloaded{hyperref}{}%
{\let\NoHyper\relax\let\endNoHyper\relax}}
\makeatother
\begin{document}
\setlength{\mymulticolwidth}{\dimexpr 2.5cm + 3.5cm + 2.5cm + 4\tabcolsep\relax}
\newcommand{\mymulticol}[1]{%
\multicolumn{3}{p{\mymulticolwidth}|}{#1}%
}
\begin{longtable}{| p{3.5cm} | p{2.5cm} | p{3.5cm} | p{2.5cm} |}
\caption{Use case detail}\label{chap3:tab1}\\
\multicolumn{4}{c}{}\\
\endfirsthead
\multicolumn{4}{c}{\tablename\ \thetable\ -- \textit{Continued from previous page}}\\
\multicolumn{4}{c}{}\\
\hline
\endhead
\hline \multicolumn{4}{r}{\tablename\ \thetable\ -- \textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
%
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case ID: & \multicolumn{3}{l|}{1}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case Name: & \multicolumn{3}{l|}{FIXME - Section Name}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Created by: & & Date created: &\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Actors & \multicolumn{3}{l|}{Doctor}\\
& \multicolumn{3}{l|}{Patient}\\
& \multicolumn{3}{l|}{Patients' Database}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Description: & \mymulticol{%
The doctor logs into the system, creates/updates the patient medical record, prints the informed consent form and collects it after the patient has signed it.}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Preconditions: & \multicolumn{3}{e{\mymulticolwidth}|}{%
\item The doctor is logged into the web software.
\item There is no record for the patient on the patients' database.}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Postconditions: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Trigger: & \mymulticol{%
The doctor logs in the system and presses the \textit{Login} button}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Normal flow: & \multicolumn{3}{e{\mymulticolwidth}|}{%
\item the doctor clicks on the \textit{Patients} icon;
\item the doctor clicks on the \textit{Add} button;
\item the doctor prints the consent form by clicking on the dedicated button;
\item the doctor fills in the patient's details;
\item the doctor collects the signed patient's consent form and ticks the dedicated check box;
\item the doctor saves the patient's record by clicking the \textit{Save} button.}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Alternative flows: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Exceptions: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Notes and issues: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
\end{longtable}
\end{document}
该原理可以扩展,以包为例enumerate
:
\documentclass{article}
\usepackage[
hmargin=15mm,
vmargin=15mm,
]{geometry}
\usepackage{longtable}
\usepackage{array}
\usepackage{enumerate}
\setlength{\extrarowheight}{2pt}
\newlength\mymulticolwidth
\makeatletter
\newcolumntype{e}[1]{%--- Enumerated cells ---
>{\minipage[t]{\linewidth}%
\NoHyper% Hyperref adds a vertical space because of anchor whatsit.
\let\\\tabularnewline
\settowidth{\leftmargini}{9.\hspace{\labelsep}}%
\enumerate
\addtolength{\rightskip}{0pt plus 50pt}% for raggedright
\setlength{\itemsep}{-\parsep}}%
p{#1}%
<{\@finalstrut\@arstrutbox\endenumerate
\endNoHyper
\endminipage}}
\newcolumntype{E}[2]{%--- Enumerated cells ---
>{\minipage[t]{\linewidth}%
\NoHyper% Hyperref adds a vertical space because of anchor whatsit.
\let\\\tabularnewline
\settowidth{\leftmargini}{9a.\hspace{\labelsep}}%
\enumerate[{#2}]%
\addtolength{\rightskip}{0pt plus 50pt}% for raggedright
\setlength{\itemsep}{-\parsep}}%
p{#1}%
<{\@finalstrut\@arstrutbox\endenumerate
\endNoHyper
\endminipage}}
\AtBeginDocument{%
\@ifpackageloaded{hyperref}{}%
{\let\NoHyper\relax\let\endNoHyper\relax}}
\makeatother
\begin{document}
\setlength{\mymulticolwidth}{\dimexpr 2.5cm + 3.5cm + 2.5cm + 4\tabcolsep\relax}
\newcommand{\mymulticol}[1]{%
\multicolumn{3}{p{\mymulticolwidth}|}{#1}%
}
\begin{longtable}{| p{3.5cm} | p{2.5cm} | p{3.5cm} | p{2.5cm} |}
\caption{Use case detail}\label{chap3:tab1}\\
\multicolumn{4}{c}{}\\
\endfirsthead
\multicolumn{4}{c}{\tablename\ \thetable\ -- \textit{Continued from previous page}}\\
\multicolumn{4}{c}{}\\
\hline
\endhead
\hline \multicolumn{4}{r}{\tablename\ \thetable\ -- \textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
%
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case ID: & \multicolumn{3}{l|}{1}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Use Case Name: & \multicolumn{3}{l|}{FIXME - Section Name}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Created by: & & Date created: &\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Actors & \multicolumn{3}{l|}{Doctor}\\
& \multicolumn{3}{l|}{Patient}\\
& \multicolumn{3}{l|}{Patients' Database}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Description: & \mymulticol{%
The doctor logs into the system, creates/updates the patient medical record, prints the informed consent form and collects it after the patient has signed it.}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Preconditions: & \multicolumn{3}{e{\mymulticolwidth}|}{%
\item The doctor is logged into the web software.
\item There is no record for the patient on the patients' database.}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Postconditions: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Trigger: & \mymulticol{%
The doctor logs in the system and presses the \textit{Login} button}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Normal flow: & \multicolumn{3}{e{\mymulticolwidth}|}{%
\item the doctor clicks on the \textit{Patients} icon;
\item the doctor clicks on the \textit{Add} button;
\item the doctor prints the consent form by clicking on the dedicated button;
\item the doctor fills in the patient's details;
\item the doctor collects the signed patient's consent form and ticks the dedicated check box;
\item the doctor saves the patient's record by clicking the \textit{Save} button.}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Alternative flows: & \multicolumn{3}{E{\mymulticolwidth}{1{a}.}|}{%
\item lorem ipsum
\item lorem ipsum
\item lorem ipsum}\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Exceptions: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
% --------------------------------------------------------------------------------------------------------------
Notes and issues: & \multicolumn{3}{l|}{ }\\
% --------------------------------------------------------------------------------------------------------------
\hline
\end{longtable}
\end{document}