2

I've created the following table with help of @Zarko. Now I have some questions about layout.

Code:

\documentclass[11pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{xcolor,colortbl}

\begin{document}
\begin{table}[h]
        \begin{tabular}{|p{.1cm}|p{.1cm}|p{.1cm}|p{.1cm}|p{.1cm}|p{3.5cm}|p{2cm}|p{2cm}|}
\hline
\multicolumn{6}{|c|}{ \textbf{ I have to put here very long definitions.  QUESTION1}}&
\textbf{I have to put here very long definitions}
&\textbf{I have to put here very long definitions}\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|c|}{\textbf{I have to put here very long definitions}
}&&\\
\hline
1&2&3 QUESTION2&4&5&too many substances QUESTION3&&\\
\hline
1&2&3&4&5&too many substances QUESTION4&&\\
\hline
1&2&3&4&5&too many substances&&\\
\hline
1&2&3&4&5&too many substances&&\\
\hline
1&2&3&4&5&too many substances&&\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|c|}{I have to put here very long definitions 
(some subdefinitions)
}&&\\
\hline
\multicolumn{3}{|c|}{12345678}&\multicolumn{3}{|c|}{too many substance}&&\\
\hline
\multicolumn{3}{|c|}{12345678}&\multicolumn{3}{|c|}{too many substance}&&\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|c|}{again long definitions}&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla QUESTION5&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|c|}{again long definitions) 
(again long definitions)
}&&\\
\hline
\multicolumn{3}{|c|}{\multirow{4}{*}{12345678} }&

\multicolumn{3}{|c|}{too many substances,bla,bla,bla QUESTION6}&&\\
\cline{4-8}
\multicolumn{3}{|c|}{}&1&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&2&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&3&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\hline
\multicolumn{3}{|c|}{\multirow{4}{*}{12345678} }&
\multicolumn{3}{|c|}{too many substances,bla,bla,bla}&&\\
\cline{4-8}
\multicolumn{3}{|c|}{}&1&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&2&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&3&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\hline
\multicolumn{3}{|c|}{\multirow{4}{*}{12345678} }&
\multicolumn{3}{|c|}{too many substances,bla,bla,bla}&&\\
\cline{4-8}
\multicolumn{3}{|c|}{}&1&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&2&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&3&\multicolumn{2}{|c|}{}&&\\\cline{4-8}
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|c|}{Conclusions}&&\\
\hline
\end{tabular}
\end{table}
\end{document}

Layout:enter image description here

Question1: Why I can't center this text like in 3. and 4. columns in this row?(I tried to use \centering)

Question2: I arranged the cell widths for the tabular, but why is the cell of number 3 is larger then other numbers(1,2,4,5)?

Question3: I've tried to reduce the cell width here, but it did not help to avoid leaving so many spaces for a little text. How can I manage it? For example, why I cannot write the Question4 after my text and why .tex put it to the next line?

Question5 shows my question above better. Why .tex put here every new word to the next line?

Question6: I've cut my table here for fitting to the page? What should I do if I have a larger table?

I hope that such a questionnaire fit to stack-format.

2 Answers 2

4

I hope that such a questionnaire fit to stack-format.

Not really, it is much better to ask 1 question per posted question, but anyway. Also the question is tagged tabularx but you don't seem to be using that.

Question1: Why I can't center this text like in 3. and 4. columns in this row?(I tried to use \centering)

Not sure what you mean here.

Question2: I arranged the cell widths for the tabular, but why is the cell of number 3 is larger then other numbers(1,2,4,5)?

Column 3 is forced wide as you have

\multicolumn{3}{|c|}{12345678}

and that text is wider than fits in the specified width, so the last spanned column (3 here) is made wider, you can see this, just by looking how the | rules line up.

Question3: I've tried to reduce the cell width here, but it did not help to avoid leaving so many spaces for a little text. How can I manage it? For example, why I cannot write the Question4 after my text and why .tex put it to the next line?

That text is in a column of specified width 3.5cm and Question 4 does not fit, the following column is empty in all cases (the &&) so you should probably not have the following column, and then make that column wider.

Question5 shows my question above better. Why .tex put here every new word to the next line?

This is same issue as the previous question, you are justifying the text to a narrow width, not in the area marked by the vertical rules. The text is set to the widths you specify in p but the column and its rule are extended because

I have to put here very long definitions

does not fit in the specified width.

Question6: I've cut my table here for fitting to the page? What should I do if I have a larger table?

Use the longtable package.


Something like this, although it is still too wide (hence the negative left skip to steal the left margin) probably you shoud use a smaller fone size such as \small and adjust the column widths again.

\documentclass[11pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{array,multirow,longtable}
\usepackage[table]{xcolor}
\usepackage{calc}

\begin{document}

\setlength{\LTleft}{-40pt}
\setlength{\LTright}{\fill}

\begin{longtable}{|p{.2cm}|p{.2cm}|p{.2cm}|p{.2cm}|p{.2cm}|>{\raggedright}p{6.5cm}|p{2cm}|p{2cm}|}
\hline
\multicolumn{6}{|p{7cm+10\tabcolsep+5\arrayrulewidth}|}{ \textbf{ I have to put here very long definitions.  QUESTION1}}&
\textbf{I have to put here very long definitions}
&\textbf{I have to put here very long definitions}\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|p{7cm+10\tabcolsep+5\arrayrulewidth}|}{\textbf{I have to put here very long definitions}
}&&\\
\hline
1&2&3&4&5&too many substances QUESTION3&&\\
\hline
1&2&3&4&5&too many substances QUESTION4&&\\
\hline
1&2&3&4&5&too many substances&&\\
\hline
1&2&3&4&5&too many substances&&\\
\hline
1&2&3&4&5&too many substances&&\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|p{7cm+10\tabcolsep+5\arrayrulewidth}|}{I have to put here very long definitions 
(some subdefinitions)
}&&\\
\hline
\multicolumn{3}{|c|}{12345678}&\multicolumn{3}{c|}{too many substance}&&\\
\hline
\multicolumn{3}{|c|}{12345678}&\multicolumn{3}{c|}{too many substance}&&\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|p{7cm+10\tabcolsep+5\arrayrulewidth}|}{again long definitions}&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla QUESTION5&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
1&2&3&4&&too many substances,bla,bla,bla&&\\
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|p{7cm+10\tabcolsep+5\arrayrulewidth}|}{again long definitions) 
(again long definitions)
}&&\\
\hline
\multicolumn{3}{c|}{\multirow{4}{*}{12345678} }&

\multicolumn{3}{c|}{too many substances,bla,bla,bla QUESTION6}&&\\
\cline{4-8}
\multicolumn{3}{|c|}{}&1&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&2&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&3&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\hline
\multicolumn{3}{|c|}{\multirow{4}{*}{12345678} }&
\multicolumn{3}{|c|}{too many substances,bla,bla,bla}&&\\
\cline{4-8}
\multicolumn{3}{|c|}{}&1&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&2&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&3&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\hline
\multicolumn{3}{|c|}{\multirow{4}{*}{12345678} }&
\multicolumn{3}{|c|}{too many substances,bla,bla,bla}&&\\
\cline{4-8}
\multicolumn{3}{|c|}{}&1&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&2&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\multicolumn{3}{|c|}{}&3&\multicolumn{2}{c|}{}&&\\\cline{4-8}
\hline
\rowcolor[gray]{.9}[0pt][0pt]
\multicolumn{6}{|c|}{Conclusions}&&\\
\hline
\end{longtable}
\end{document}
1

In partial answer to QUESTION1 and QUESTION2. If you want more than one line you need to use a \parbox{...}{\centering ...}, which means you need to specify the width. It should be noted that when a \multicolumn is wider than the sum of the columns, all the excess will go into the last column rather than be evenly divided. You can use \makebox to force these columns to be the same width, as shown below:

\documentclass[border=.1in]{standalone}

\begin{document}
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|p{1in}|}{\centering This is a very long line which will eventually wrap around.}\\
\hline
\makebox[\dimexpr .5in - \tabcolsep]{test} & test\\
\hline
\end{tabular}
\end{document}

tabular

You must log in to answer this question.

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