1

This is my latex document:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{float} 
\usepackage{tabularx}

\begin{document}
\begin{table}[H]    

\def\arraystretch{1.5}

\begin{tabularx}{\linewidth}{|l|X|X|X|}

  \hline Use Case \#N & \multicolumn{3} {l|}{ Login } \\ \hline Goal in
  Context & \multicolumn{3}{>{\hsize=\dimexpr 3\hsize+4\tabcolsep+2\arrayrulewidth\relax}X|}
  { Per identificarsi } \\
 \hline Preconditions &
  \multicolumn{3}{l|}{ L'utente deve avere già un account } \\
 \hline Success End Conditions &
  \multicolumn{3}{l|}{ L'utente è stato identificato nel sistema } \\
 \hline Failed End Conditions &
  \multicolumn{3}{l|}{ 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 &
  \multicolumn{3}{l|}{ Attore principale dello UC } \\
 \hline Trigger & \multicolumn{3}{l|}{ Azione principale dell'attore che attiva lo UC } \\

  \hline \multirow{2}{*}{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 \multirow{2}{*}{Extensions} & Step &
  User Action & System \\
 \cline{2-4} & & & \\
 \hline
  \multirow{2}{*}{Subvariations} & Step & User Action & System \\

  \cline{2-4} & & & \\
 \hline Notes & \multicolumn{3}{l|}{} \\
 \hline


\end{tabularx}

\end{table}
\end{document}

Unfortunately when I write some long text as Lipsum... this goes out of the right margin as you can see hereenter image description here

  • How can I fix? How can I tell to Latex that if I write some long text, it goes automatically newline?

EDIT:

If I replace l with p{10cm}| in multicolumn this is what happens:

enter image description here

3
  • A \multicolumn{3}{l} overwrites the ability of X type colmns to automatically insert linebreaks where needed. Either replace l with p{...}` with "..." being an appropriate width or use \multicolumn{3}{>{\hsize=\dimexpr 3\hsize+4\tabcolsep+2\arrayrulewidth\relax}X|} as you already did in the second row of your table. Since this will get quite uncomfortable long, you could also define a costum command to avoid repeating this over and over.
    – leandriis
    Mar 18 '20 at 15:36
  • Done, but the shape of the table (square) is not drawn... SOLVED.
    – ItsGhost
    Mar 18 '20 at 15:38
  • The answer for this is really the same as that for your previous question, tex.stackexchange.com/q/533107 . Mar 18 '20 at 17:35
0

Try the following suggestion. Compare it with your MWE for seeing difference.

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

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

enter image description here

3
  • this goes off page if I write too much in cells.. how do I fix?
    – ItsGhost
    Mar 18 '20 at 20:49
  • @ItsGhost, (i) from your question was not evident of size of your table, so answer solve problem as was presented in question, (ii) if table is longer than text height, than a solution is to use long tables environments, for example longtable, xltabular, etc. This tables had not to be enclosed to table environment.
    – Zarko
    Mar 18 '20 at 21:22
  • this seems to work but where can I add a caption?
    – ItsGhost
    Mar 19 '20 at 10:06

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.