4

i have two tables, each of them has 4 columns. one is just below the other. i want to know how to make every column of the below table have same width of the column of the above table. it looks like this:

|-------|-------|-------|-------|
|       |       |       |       |
|-------|-------|-------|-------|
|       |       |       |       |
|-------|-------|-------|-------|
|       |       |       |       |
|-------|-------|-------|-------|

some space lines are here.

|-------|-------|-------|-------|
|       |       |       |       |
|-------|-------|-------|-------|
|       |       |       |       |
|-------|-------|-------|-------|

adding one more hline will make one table septable, which it looks like two tables with good vertical alignment.

\documentclass{article}

\begin{document}
\begin{tabular}[b]{|c|c|c|c|}
\hline
\textbf{Item-No.} & \textbf{name} & \textbf{cross section} & \textbf{grade}\\
\hline
\textbf{W1} & Z-column & HN350x175 -- 346x174 & Q235\\
\hline
\textbf{W17} & Horiz. support transversal hoist beam & HW100x100 & Q235\\
\hline
\hline
\textbf{P11} & longitudinal hoist beam & HN300x150 -- 300x150 & Q235\\
\hline
\end{tabular}

\end{document}

but one more thing, how to add vertical spacing between the tables?

  • 4
    The simplest thing would be to put the text between them into a \multicolumn{4}{l}. Would this be OK for your document? – Martin Scharrer Mar 17 '11 at 14:38
  • Or simply use fixed width columns? – Alan Munn Mar 17 '11 at 16:41
  • @Martin: there is no text between the two tables, just several space lines. i have added an example in the original text. now it looked like two tables. but i don't know how to add vertical space between them. – warem Mar 18 '11 at 5:16
  • @Alan: the tex source code is generated from a C program. in the programming status, i don't know how i can find a appropriate column width for every column. – warem Mar 18 '11 at 5:18
4

The simplest way to add some vertical space between the two logical tables while having the same column width is to only use one real table and add the vertical white space as \multicolumn row which includes a \vspace to make it as high as required. Note that the \multicolumn is required to disable the vertical borders in the normal cells. Without this a simple empty cell with \vspace would be enough.

You can adjust the white space with the argument of \vspace{<distance>}. The value wont be the exact distance because the cell \strut is also in effect, which adds also a certain depth. If you need exact distances you have to calculate this in.

Example Code:

\documentclass{article}

\begin{document}
\begin{tabular}[b]{|c|c|c|c|}
\hline
\textbf{Item-No.} & \textbf{name} & \textbf{cross section} & \textbf{grade}\\
\hline
\textbf{W1} & Z-column & HN350x175 -- 346x174 & Q235\\
\hline
\textbf{W17} & Horiz. support transversal hoist beam & HW100x100 & Q235\\
\hline
%
\multicolumn{4}{c}{\vspace{1cm}}\\
%
\hline
\textbf{P11} & longitudinal hoist beam & HN300x150 -- 300x150 & Q235\\
\hline
\end{tabular}

\end{document}

Result:

Result

  • 1
    "…\multicolumn is required…" You could also use: \noalign{\bigskip} (or some other vskip) – morbusg Mar 18 '11 at 10:51
  • @morbusg: Good idea. I meant something like "use \multicolumn instead of \\\hline\vspace{..}\\" to avoid the vertical cell border. – Martin Scharrer Mar 18 '11 at 10:55
  • @Martin: Ah, I see, makes sense. However, with \noalign, I believe you wouldn't need to worry about the \strut? – morbusg Mar 18 '11 at 11:17
  • @morbusg: Yes, \noalign would be better in this specific case (I simply didn't think about it). However, I think beginners would understand \multicolumn easier. Also it can also be used if some text between the tables should be added. – Martin Scharrer Mar 18 '11 at 11:24
  • @Martin: thank you for your good and clear explanation. i have used \multicolumn in my table. but i didn't think out in this way to add vertical spacing. – warem Mar 19 '11 at 0:38

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.