6

I've been trying to build a "complex" table of a certain size but I still have some problems with the spacing. As you can see in the attached pictures, some lines overlap the table row dividers, other are just random (I suspect there is some conflict with the parbox function used inside the multicolumn one). Is there any way to have a more even and pleasant spacing?

First part of the table enter image description here

\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
    Please edit the question to be a complete document so other people can use it with the same page size etc so they get the result you see – David Carlisle Jun 15 '13 at 15:46
  • Sorry, I've added the details requested! – Ales Jun 15 '13 at 15:57
6

I think you had too many columns and too much markup generally, I think I 'd do this unless you really need the lists to break over a page.

\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}

enter image description here

  • Thank you very much, the code is surely more elegant and clear compared to mine. – Ales Jun 15 '13 at 17:01
9
  • There is no need for \parbox, column type p is better regarding the vertical spacing. The width is calculated from the three column width of the default p columns. Each column get two \tabcolsep, therefore 4\tabcolsep are added for the two suppressed columns.

    \newlength\mymulticolwidth
    \setlength{\mymulticolwidth}{\dimexpr 2.5cm + 3.5cm + 2.5cm + 4\tabcolsep\relax}
    
  • The example also adds \extrarowheight of package array that is added at the top of the rows.

  • The enumerations can be set by environment enumerate with some adaptations of Donald Arsenau that defines a new column type and is shown in Danie Els' answer. I have only set \leftmargini to get rid of the large indentation. If the numbers exceed 9, then the code needs some refinement.

Example file:

\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} 

Result

The principle can be extended, example for package 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} 

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.