0

I'm a newbie with LaTeX.

This is my file:

\documentclass[a4paper]{article}
\usepackage{multirow, tabularx}
\renewcommand{\familydefault}{\sfdefault}


\begin{document}
    \begin{table}[!ht]
\renewcommand\arraystretch{1.5}
\newcommand\mcl[1]{\multicolumn{3}{l|}{#1}}

\begin{tabularx}{\linewidth}{|l|>{\hsize=0.4\hsize}X|
                                >{\hsize=1.8\hsize}X|
                                >{\hsize=0.8\hsize}X|}
    \hline 
Use Case \#N    & \mcl{Login}                               \\ 
    \hline
Goal in Context & \mcl{Per identificarsi}                   \\
    \hline 
Preconditions   & \mcl{L'utente deve avere già un account}  \\
    \hline 
Success End Conditions 
                & \mcl{L'utente è stato identificato nel sistema}       \\
    \hline 
Failed End Conditions 
                &   \multicolumn{3}{>{\hsize=\dimexpr3\hsize+6\tabcolsep+3\arrayrulewidth}X|}{ 
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero. } \\
    \hline 
Primary Actor   & \mcl{Attore principale dello UC}                      \\
    \hline 
Trigger         & \mcl{Azione principale dell'attore che attiva lo UC}  \\
    \hline 
Description     & Step  & User Action               & System            \\  \cline{2-4} 
                & 1     & L'utente clicca OK        &                   \\  \cline{2-4} 
                & 2     &                           & Mostra M1         \\  \cline{2-4} 
                & 3     & L'utente clicca Cliccami  &                   \\  \cline{2-4} 
                & 4     &                           & Chiude            \\
    \hline 
Extensions      & Step  & User Action               & System            \\  \cline{2-4} 
                &   &   &   \\
    \hline
Subvariations   & Step  & User Action               & System            \\  \cline{2-4} 
                &   &   &   \\
    \hline 
Notes           &   &   &   \\
    \hline
\end{tabularx}
    \end{table}
\end{document}

enter image description here

  • Unfortunately, what happens is - if I write a very long text - the table goes off the bottom margin of page. How can I fix it? (Note that with short text it works properly).
  • Possible duplicate: My table doesn't fit; what are my options? – Werner Mar 18 at 23:52
  • Why not use a description list instead? This will allow for pagebreaks where needed and you don't wase that much space (see all the whie space in the left column). – leandriis Mar 19 at 7:25
0

You need to use one of tables packages which enable break table over pages. For example xltabular package which is combination of the longtable and tabularx package:

\documentclass[a4paper]{article}
\usepackage{makecell, xltabular}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\begingroup
    \setcellgapes{2pt}
    \makegapedcells
    \newcommand\mcl[1]{\multicolumn{3}{l|}{#1}}
\begin{xltabular}{\linewidth}{|l|>{\hsize=0.4\hsize}X|
                                >{\hsize=1.8\hsize}X|
                                >{\hsize=0.8\hsize}X|}
\caption{Caption text ...}  % <--- CAPTION, only on table beginning
\label{tab:tale-1}          \\
    \hline
\endfirsthead
%\caption[]{Caption text ... (cont.) }\\  % <--- in case that you like to repeat it on each page
    \hline
\endhead
    \hline
\endfoot
\endlastfoot
Use Case \#N    & \mcl{Login}                               \\
    \hline
Goal in Context & \mcl{Per identificarsi}                   \\
    \hline
Preconditions   & \mcl{L'utente deve avere già un account}  \\
    \hline
Success End Conditions
                & \mcl{L'utente è stato identificato nel sistema}       \\
    \hline
Failed End Conditions
                &   \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep+2\arrayrulewidth}X|}{
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer hendrerit turpis enim, suscipit tincidunt enim tincidunt egestas. Sed pretium rhoncus elit, at maximus nibh. Etiam ut ipsum sit amet nisi mattis interdum. Mauris a mi tellus. Integer ultricies risus eget enim molestie pretium. Nunc tempor facilisis mauris, ut volutpat libero. } \\
    \pagebreak  
Primary Actor   & \mcl{Attore principale dello UC}                      \\
    \hline
Trigger         & \mcl{Azione principale dell'attore che attiva lo UC}  \\
    \hline
Description     & Step  & User Action               & System            \\  \cline{2-4}
                & 1     & L'utente clicca OK        &                   \\  \cline{2-4}
                & 2     &                           & Mostra M1         \\  \cline{2-4}
                & 3     & L'utente clicca Cliccami  &                   \\  \cline{2-4}
                & 4     &                           & Chiude            \\
    \hline
Extensions      & Step  & User Action               & System            \\  \cline{2-4}
                &   &   &   \\
    \hline
Subvariations   & Step  & User Action               & System            \\*  \cline{2-4}
                &   &   &   \\
    \hline
Notes           &   &   &   \\
    \hline
\end{xltabular}
    \endgroup
\end{document}

enter image description here

(red lines indicate page layout)

For showed appearance of table you need to compile MWE at least twice.

Note: table break can be only between rows. This mean that any cell content should be fit in one page. Automatic break of table not always break table at sensible point. Therefore I insert \pagebreak command in table at place where I estimate that is more sensible. However, you can delete this command and see if then obtained result is acceptable to you.

| improve this answer | |
  • Maybe you could add that pagebreaks are only possible between rows as opposed to within rows. In OP's example it looks like they have a single row with a lot of text. In this specific case, longtable might alos not give the desired output. – leandriis Mar 19 at 7:25
  • 1
    @leandriis, you are right. I just write a note with this information when your comment arrive. Due to our government measure against covit-19 now all schools and university perform (interactive) distance learning. Consequently all networks in state are overwhelm with traffic and now become very slow, i.e. with increased response time. So for finish my short comment take me almost five minutes to upload it :-( – Zarko Mar 19 at 7:39
  • This seems to work but how can I add caption? – ItsGhost Mar 19 at 10:06
  • @ItsGhost, your MWE not contain caption, so I didn't add it. Now is added. BTW, your reputation crossed threshold for voting rights! Now you can also up-votes received answers (by clicking on up-pen at top left side of answer). – Zarko Mar 19 at 12:09

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.