1

I am trying to generate a table that requires different row widths. The first column should have as little width as possible (just to print single digit 1,2,3 upto 9), whereas column 3 (where I have put *) should be 20mm wide. The rest I want 1cm wide.

But my following code just produces an equal column width table. Strangly, I could increase the row height by using \vspace{15mm}.

How to control (specify absolute value like 3mm, 23mm) the width and height of individual rows and columns in tabu (not in tabular)? It's very important for me to be able to specify width and height of individual rows and columns. It seems tex is coming in my way :( I wish to use tabu as I find it more convenient to do some other stuff.

\documentclass{article}
\usepackage{tabu}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabu} spread 0pt {|*{12}{[0.5pt]X[c,m]|}}
\hline
1  \vspace{5mm} & & \hspace{20mm}* & & & & & & & & & \\  \hline
2  \vspace{15mm} & & & & & & & & & & & \\  \hline
\end{tabu}
\end{table}

\end{document}
1

I got some information here here. It is about tabular but it also worked for tabu.

Here is working code:

\documentclass{article}
\usepackage{tabu}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabu} spread 0pt {|@{}X[c,m]@{}|*{11}{[0.5pt]X[c,m]|}}
\hline
1\vspace{5mm} & & \hspace{20mm}* & & & & & & & & & \\  \hline
2\vspace{15mm} & & & & & & & & & & & \\  \hline
\end{tabu}
\end{table}

\end{document}
0

Since OP already made answer on his question, it seems that it found what he has looked for. However, comparing obtained results width request in his question, if I understand them correctly:

  • width of the first column be small as possible
  • width of the next ten columns is 20 mm
  • width of last column is 10 mm

For the last request, as far as I know, no one package for setting tables doesn't provide macro for explicit setting the height of cell/row. It is automatically adjusted to the height of cell with highest content. Consequently, if one wish determine minimum height of cell, he can do this on the way as show OP in his answer or use \rule[<offset>]{<width>}{<height>} with set width to zero.

Easier is width cell width. Normally tabu set cell width to width its content. For explicit determination it offer mechanism for determination ratios between widths and parameter for determination of table width. From data in questions follows, that width of table is (if the minimum width of the first column is 4mm):

1 x 4mm + 10 x 20mm + 1 x 10mm = 214mm

what can not be fit in A4 sheet in portrait orientation, it can be fit only in landscape orientation.

Code:

\documentclass[border=2mm,
               preview]{standalone}
\setlength\textwidth{250mm}
\usepackage{array,tabu}
    \begin{document}   
\begin{table}[htbp]
\centering
    \caption{OP answer}
\begin{tabu} spread 0pt {|@{}X[c,m]@{}|*{11}{[0.5pt]X[c,m]|}}
    \hline
1  \vspace{5mm} & & \hspace{20mm}* & & & & & & & & & \\ \hline
2  \vspace{15mm} & & & & & & & & & & & \\               \hline
\end{tabu}
\end{table}

\begin{table}
    \caption{Proposed solution with different determination of rows heights}
\abovetabulinesep=1mm
\belowtabulinesep=1mm
\begin{tabu}to 214mm{|X[0.4,c,m]|*{10}{X[2,cm]|}X[1,c,m]|}
    \hline
1\vspace{5mm}     & & * & & & & & & & & &    \\  \hline
\vspace{2.5mm}2\vspace{2.5mm}     & & * & & & & & & & & &    \\  \hline
3\rule{1mm}{5mm}  & & * & & & & & & & & &    \\  \hline
4 \rule{1mm}{5mm}  & & * & & & & & & & & &    \\  \hline
5\rule{1mm}{15mm} & & * & & & & & & & & &    \\  \hline
6 \rule{1mm}{15mm} & & * & & & & & & & & &    \\  \hline
7\rule{1mm}{15mm} & xxx xxx xxx xxx xxx xxx xxx xxx
                      xxx xxx xxx xxx xxx xxx xxx xxx
                       & * & & & & & & & & &    \\  \hline
\end{tabu}
\end{table}
    \end{document}

enter image description here

In code the with of rules is intentionally set to 1mm, that can be seen where they are in cells. Last row show, that the height of row is adopted to the highest content in cells. For better looking I add \abovetabulinesep=1mm and \belowtabulinesep=1mm.

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.