4

I'm trying to draw a tabular in which the column lenghts are fixed. The problems occur when I use multirow and multicolumn, as the text is very long. This is my (not working) code

\begin{tabular}{p{0.40\linewidth}|p{0.10\linewidth}|p{0.40\linewidth}}
    \multicolumn{3}{c}{Utilizzare le reti e gli strumenti informatici nelle attività di studio, ricerca e approfondimento}
    CRITERI/EVIDENZE    &   \multicolumn{2}{c}{LIVELLI DI PADRONANZA} \\
    \hline
    \multirow{4}{*}{Capacità di produrre un testo in forma multimediale, in forma di video o di presentazione}      &   
        A & Utilizza diverse tecniche informatiche e strumenti con  autonomia ed efficacia \\
        B & Utilizza diverse tecniche informatiche e strumenti con  una certa autonomia \\
        C & Si orienta nell’utilizzare diverse tecniche informatiche \\
        D & Utilizza lentamente gli strumenti informatici e su indicazione dell’insegnante.
\end{tabular}

and this is what I want to create

1
  • 1
    Your problem is the use of * for the width of the \multirow, as it means to use the 'natural width' of the text, which is large for a large text. As you can see in the answers given, = should be used instead. Aug 18, 2021 at 13:21

3 Answers 3

4

Here is a correct code. I added the possibility to have a table that uses the whole text width with tabularx. Note that the first argument in \multirow is not the number of rows, but the number of lines, to take into account the case of adjacent multiline cells.

\documentclass{article}
\usepackage[italian]{babel}
\usepackage{array, multirow}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\usepackage{tabularx}

\begin{document}

\begin{table}
\centering\setlength{\extrarowheight}{3pt}
\begin{tabular}{|p{0.40\linewidth}|l|p{0.40\linewidth}|}
\hline
    \multicolumn{3}{|p{0.9\linewidth}|}{Utilizzare le reti e gli strumenti informatici nelle attività di studio, ricerca e approfondimento}\\ \hline
    CRITERI/EVIDENZE & \multicolumn{2}{c|}{LIVELLI DI PADRONANZA} \\
    \hline
    \multirow{11}{=}{Capacità di produrre un testo in forma multimediale, in forma di video o di presentazione}
        & A & Utilizza diverse tecniche informatiche e strumenti con autonomia ed efficacia \\
     & B & Utilizza diverse tecniche informatiche e strumenti con una certa autonomia \\
     & C & Si orienta nell’utilizzare diverse tecniche informatiche \\ & D & Utilizza lentamente gli strumenti informatici e su indicazione dell’insegnante. \\
\hline
\end{tabular}
\vskip 2em

\begin{tabularx}{\textwidth}{|X|l|X|}
\hline
    \multicolumn{3}{|p{\dimexpr\linewidth-2\tabcolsep}|}{\centering Utilizzare le reti e gli strumenti informatici nelle attività di studio, ricerca e approfondimento}\\ \hline
    CRITERI/EVIDENZE & \multicolumn{2}{c|}{LIVELLI DI PADRONANZA} \\
    \hline
    \multirow{10}{=}{Capacità di produrre un testo in forma multimediale, in forma di video o di presentazione}
        & A & Utilizza diverse tecniche informatiche e strumenti con autonomia ed efficacia \\
     & B & Utilizza diverse tecniche informatiche e strumenti con una certa autonomia \\
     & C & Si orienta nell’utilizzare diverse tecniche informatiche \\ & D & Utilizza lentamente gli strumenti informatici e su indicazione dell’insegnante. \\
\hline
\end{tabularx}
\end{table}

\end{document} 

enter image description here

2
  • Thanks a lot. Two another questions: - what to do in order to resize the lenght of the first column "CRITERI/EVIDENZE" using tabularx option? - what to do in order to center the text "CRITERI/EVIDENZE"?
    – tomino
    Aug 19, 2021 at 8:42
  • @tomino: For the first point, you can change the ratio of the widths of the two X columns, using the syntax >{\hsize= x1\hsize}X and similarly for the second X column, with the condition that x1 + x2 = 2 (more generally, the sum of the coefficients must be equal to the total X columns). To centre the first column head, the simplest would be to add \centering before `CRITERI/EVIDENZE’.
    – Bernard
    Aug 19, 2021 at 9:00
3

Try the following:

\documentclass{article}
\usepackage{multirow, tabularx}
\usepackage[table]{xcolor}

%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\noindent%
    \begin{tabularx}{\linewidth}{|X|c|X|}
    \hline
\multicolumn{3}{|p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}|}{Utilizzare le reti e gli strumenti informatici nelle attività di studio, ricerca e approfondimento}    \\
    \hline
    CRITERI/EVIDENZE    &   \multicolumn{2}{c|}{LIVELLI DI PADRONANZA} \\
    \hline
\multirow{11}{=}{Capacità di produrre un testo in forma multimediale, in forma di video o di presentazione}      
&       A & Utilizza diverse tecniche informatiche e strumenti con  autonomia ed efficacia \\
&       B & Utilizza diverse tecniche informatiche e strumenti con  una certa autonomia \\
&       C & Si orienta nell’utilizzare diverse tecniche informatiche \\
&       D & Utilizza lentamente gli strumenti informatici e su indicazione dell’insegnante.\\
    \hline
    \end{tabularx}
\end{document}

enter image description here

(red lines indicate text borders)

Addendum: For exercise, solution with use of new table package tabularray:

\documentclass{article}
\usepackage{tabularray}
\usepackage[table]{xcolor}

\begin{document}
\noindent%
    \begin{tblr}{hlines, vlines,
                 colspec={X c X},
                 hspan=minimal,
                 }
\SetCell[c=3]{c, yellow!30}    
        Utilizzare le reti e gli strumenti informatici nelle attività di studio,
        ricerca e approfondimento                                                           \\
CRITERI/EVIDENZE
    &   \SetCell[c=2]{h}    LIVELLI DI PADRONANZA                                            \\
\SetCell[r=4, c=1]{c}   Capacità di produrre un testo in forma multimediale, 
                        in forma di video o di presentazione
    & A & Utilizza diverse tecniche informatiche e strumenti con  autonomia ed efficacia    \\
    & B & Utilizza diverse tecniche informatiche e strumenti con  una certa autonomia       \\
    & C & Si orienta nell’utilizzare diverse tecniche informatiche                          \\
    & D & Utilizza lentamente gli strumenti informatici e su indicazione dell’insegnante.   \\
    \end{tblr}
\end{document}

enter image description here

4
  • 1
    You don't need to set \dimexpr\linewidth-2\tabcolsep-4\arrayrulewidth\relax with tabularray, just use optionhspan=minimal.
    – L.J.R.
    Aug 19, 2021 at 1:47
  • L.J.R., thank you very much. I looking for in package documentation how to define multi-column width, but didn't find any example for this :-(. Now I check gain and found description for it. Answer is corrected now:-).
    – Zarko
    Aug 19, 2021 at 6:22
  • Thanks! A question for the tabularx example: how to do if I want to create a hline only under "D | Utilizza lentamente..." ? I would like to expand this table with another gropu of ABCD levels but with the same first column.
    – tomino
    Aug 19, 2021 at 9:02
  • @tomino, new problem, new question ;-). I do not understand what is your problem. To write more table rows? Just add them. Change horizontal lines (\cline{...} instead of \hline or vice versa)?. Do on the similar way as are already done. Please clarify!
    – Zarko
    Aug 19, 2021 at 9:20
1

With {NiceTabularX} of nicematrix (≥ 6.0 of 2021-08-10).

In that environment similar to the classical {tabularx} of the eponymous package, you have a command \Block to merge cells both horizontally and vertically.

For the vertical block, you specify the number of rows (and not the number of physical lines). However, for the horizontal block, you have to put a parbox with the correct width previously computed.

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}


\begin{document}

\newlength{\mylength}
\setlength{\mylength}{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}

\begin{table}
\begin{NiceTabularX}{\linewidth}{|X|c|X|}[cell-space-limits=3pt]
\hline
\Block[fill=yellow!15]{1-3}{\parbox{\mylength}{Utilizzare le reti e gli strumenti informatici nelle attività di studio, ricerca e approfondimento}}    \\
\hline
CRITERI/EVIDENZE    & \Block{1-2}{LIVELLI DI PADRONANZA} \\
\hline
\Block[l]{4-1}{Capacità di produrre un testo in forma multimediale, in forma di video o di presentazione}      
& A & Utilizza diverse tecniche informatiche e strumenti con  autonomia ed efficacia \\
& B & Utilizza diverse tecniche informatiche e strumenti con  una certa autonomia \\
& C & Si orienta nell’utilizzare diverse tecniche informatiche \\
& D & Utilizza lentamente gli strumenti informatici e su indicazione dell’insegnante.\\
\hline
\end{NiceTabularX}
\end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .