0
\begin{longtable}{p{0.5cm}p{4cm}p{2cm}|p{2cm}p{2cm}|p{2cm}|}
\cline{4-6}
 &  &  & \multicolumn{3}{c|}{Percentages and averages} \\ \hline
\multicolumn{1}{|l|}{Nr.} & \multicolumn{1}{p{4cm}|}{Question Question Question Question Question Question Question Question Question Question Question Question Question} & Answers & Pulukan & Tumbak Bayuh & Denpasar \\ \hline
\multicolumn{1}{|l|}{\multirow{2}{*}{23}} & \multicolumn{1}{p{4cm}|}{\multirow{2}{*}{Do you know of any organizations that can collect plastic from you? Do you know of any organizations that can collect plastic from you?}} & Yes & \% & \% & \% \\ \cline{3-6} 
\multicolumn{1}{|l|}{} & \multicolumn{1}{l|}{} & No & \% & \% & \% \\ \hline
\end{longtable}

enter image description here

Does anybody know how to solve this problem? Thank you in advance!

  • Welcoma to TeX SX! Why all those \multicolumn{1}{|l|}{...}? – Bernard Nov 15 '19 at 16:19
  • I used a table generator, so it was done automatically. Is there a better way to do this? The last four cells at the lowest row are divided into two rows. Difficult to see with the sentence going out of its cell. – E Hermans Nov 15 '19 at 16:23
  • The code in our question is not compilable, even if I add a documentclass and the relevant packages – leandriis Nov 15 '19 at 16:31
  • The second argument of \multicolumn{1}{p{c|}{Question .....} is wrong. Either you wanted c OR p{some length}. – leandriis Nov 15 '19 at 16:32
  • Welcome to TeX.SE! Please include a complete, compilable example in your question; it makes it much easier to help you. – dgoodmaniii Nov 15 '19 at 16:45
2

Here is away to do it with a simpler code: I use the xltabular environment, which brings the functionalities of longtable to tabularx, so the longtable does not overflows into the margin. I added cellspace , which defines a minimal vertical padding in cells of columns with specifier prefixed with the letter S(or C if you load siunitx).

\documentclass{article}
\usepackage{ragged2e}
\usepackage{xltabular}
\usepackage{longtable}
\usepackage{array, multirow, bigstrut, cellspace}
\setlength{\cellspacetoplimit}{3pt}
\setlength{\cellspacebottomlimit}{3pt}
\addparagraphcolumntypes{X}

\begin{document}

\setlength{\tabcolsep}{4pt}
\setlength{\bigstrutjot}{6.2ex}
 \begin{xltabular}{\linewidth}{|Sl>{\hsize=1.6\hsize\RaggedRight}S{X}|Sl|*{3}{>{\hsize=0.8\hsize\arraybackslash}X|}}
\cline{4-6}
  \multicolumn{3}{c|}{} & \multicolumn{3}{Sc|}{Percentages and averages} \\ \hline
Nr. & Question Question Question Question Question Question Question Question Question Question Question Question Question & Answers & Pulukan & Tumbak Bayuh & Denpasar \\ \hline
23 & \smash{\parbox[t]{\hsize}{Do you know of any organizations that can collect plastic from you? Do you know of any organizations that can collect plastic from you?}} & Yes \bigstrut[b] & \% & \% & \% \\ \cline{3-6}
& & No \bigstrut[b] & \% & \% & \% \\ \hline
\end{xltabular}

\end{document} 

enter image description here

  • Thanks for editing, @Zarko! – Bernard Nov 15 '19 at 18:42
  • \rule{0pt}{2.5ex} shifts the text "Do you know..." a little bit down. Could you please explain why you added this piece of code? – leandriis Nov 15 '19 at 19:09
  • The text is shifted without this \rule – I suspect it is linked with the S pre-specifier which works in the following cell, but doesn't work with the X column, so I added an invisible rule as a workaround. – Bernard Nov 15 '19 at 19:15
  • Interesting. I can see a vertical shift in the screenshot you atached. I can also reproduce this shift on my system. If I on the other hand remove the mentioned \rule, I get the following that at least to me does not look shifted: i.stack.imgur.com/Fxz2i.png – leandriis Nov 15 '19 at 19:24
  • Finally, I removed the \multirow (I think it's the reason why S does not work)) and used a smashed \parbox instead. – Bernard Nov 15 '19 at 19:28
0

Here are three more suggestions:

\documentclass{article}
\usepackage{geometry}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage{xltabular}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize}
\usepackage{booktabs}
\begin{document}

\begin{longtable}{|l|p{4cm}|l|l|l|l|}
\cline{4-6}
\multicolumn{1}{l}{} & \multicolumn{1}{l}{} &  & \multicolumn{3}{c|}{Percentages and averages} \\ \hline
Nr. & Question Question Question Question Question Question Question Question Question Question Question Question Question & Answers & Pulukan & Tumbak Bayuh & Denpasar \\ \hline
\multirow{2}{*}{23} & \multirow{6}{=}{Do you know of any organizations that can collect plastic from you? Do you know of any organizations that can collect plastic from you?} & Yes & \% & \% & \% \\ 
 & & & & & \\
 & & & & & \\ \cline{3-6}
 & & No & \% & \% & \% \\ 
 & & & & & \\
 & & & & & \\ \hline
\end{longtable}


\begin{landscape}
\begin{xltabular}{\linewidth}{|l|X|l|l|l|l|}
\cline{4-6}
\multicolumn{1}{l}{} & \multicolumn{1}{l}{} &  & \multicolumn{3}{c|}{Percentages and averages} \\ \hline
\thead{Nr.} & \thead{Question} & \thead{Answers} & \thead{Pulukan} & \thead{Tumbak\\ Bayuh} & \thead{Denpasar} \\ \hline
\multirow{2}{*}{23} & \multirow{2}{=}{Do you know of any organizations that can collect plastic from you? Do you know of any organizations that can collect plastic from you?} & Yes & \% & \% & \% \\\cline{3-6}
 & & No & \% & \% & \% \\ \hline
\end{xltabular}

\begin{xltabular}{\linewidth}{lXllll}
\toprule
\multicolumn{1}{l}{} & \multicolumn{1}{l}{} &  & \multicolumn{3}{c}{Percentages and averages} \\ \cmidrule{4-6} 
\thead{Nr.} & \thead{Question} & \thead{Answers} & \thead{Pulukan} & \thead{Tumbak\\ Bayuh} & \thead{Denpasar} \\ 
\midrule
\multirow{2}{*}{23} & \multirow{2}{=}{Do you know of any organizations that can collect plastic from you? Do you know of any organizations that can collect plastic from you?} & Yes & \% & \% & \% \\
 & & No & \% & \% & \% \\ \bottomrule
\end{xltabular}
\end{landscape}
\end{document}

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.