The following is probably what you're after:
\documentclass[10pt]{article}
\begin{document}
\section{A}
\begin{tabular}{|l|l|l|l|}
\hline \multicolumn{4}{|l|}{1} \\
\hline \multicolumn{3}{|l|}{2} & 14 \\
\hline 3 & \multicolumn{2}{|l|}{7} & 15 \\
\hline 4 & 8 & \multicolumn{2}{|l|}{12} \\
\hline
\end{tabular}
\section{B}
\begin{tabular}{|l|l|l|l|}
& & \phantom{12} & \\[-\normalbaselineskip] % fake/empty row
\hline \multicolumn{4}{|l|}{1} \\
\hline \multicolumn{3}{|l|}{2} & 14 \\
\hline 3 & \multicolumn{2}{|l|}{7} & 15 \\
\hline 4 & 8 & \multicolumn{2}{|l|}{12} \\
\hline
\end{tabular}
\section{Goal}
I would like to have a table as in section B but without the third (empty) row.
\end{document}
The motivation behind this solution stems from what is commonly used in the tabbing
environment where you specify the tabbing intervals and then \kill
the row.
Note that you don't need multicol
for this, since the default tabular
is supported in LaTeX.
I first thought in an answer like that:
\documentclass{article}
\usepackage{array}
\usepackage{rotating}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ccc}
\toprule
\begin{sideways} Lengthy words which \end{sideways} &
\begin{sideways} make my columns too wide like \end{sideways} &
\begin{sideways} antidisestablishmentarianism \end{sideways} \\
\midrule
1 & 0 & 0\\
3 & 7 & 5\\
\bottomrule
\end{tabular}
\end{document}
But I believe that this is point again to the wrong target. Although you can wrap the headings with p
columns, or tabularx
or using multicolumns, o rotate 90º the headings, o some other trick, there are not a good LaTeX solution for this, because the table still will have probably a bad looking design. Just compare these four tables:
The first table made with tabularx
have horrible headings expanding in four lines and still a lot of space between columns. If you want reduce this space (second table) the headngs are even longer (more than horrible). And rotate headings as in the above MWE force to the reader to do some fun neck exercises. LaTeX can do the best with the given text, but not a miracle. The main problem is the bad design of the table, and the solution is the re-desing of the table. What table is better?
I know that this is too obvious, and surely is not considered for some good reason in this case, but in general the best solutions for long headings just are (1) use shorter headers (including using acronyms, predefined labes, etc.) or (2) transposing columns and rows:
\documentclass[]{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{lcc}
\toprule
Some long to explain & a & b \\
\midrule
Lengthy words which & 1 & 3 \\
make my columns too wide like & 0 & 7 \\
antidisestablishmentarianism & 0 & 5 \\
\bottomrule
\end{tabular}
Best Answer
I really like booktabs, it creates great, high quality tables (when I say quality I mean that they are really easy to read and look very clean). I feel weird when seeing a table with a lot of cluttered
\hline
s and\cline
s everywhere...