0

I have looked through so many tutorials regarding tables, vertical alignment, tried to do it on my own, tried to do it with excel2latex Excel addin - still having troubles with my table. I would really appreciate your help.

\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
\toprule
\multirow{2}[4]{*}{long text} & \multirow{2}[4]{*}{text} & 
\multirow{2}[4]   {*}{\begin{sideways}text\end{sideways}} & 
\multirow{2}[4]  {*}{\begin{sideways}vertical long text\end{sideways}} &
\multicolumn{6}{c|}{long text} \\
\cmidrule{5-10}          &       &       &       & 1    & 2    & 3     & 4    & 5     & 6 \\
\midrule
...    & ...    & ...    & ...    & ...   & ...   & ...    & ...   & ...     & ...  \\
...    & ...    & ...    & ...    & ...   & ...   & ...     & ...  & ...     & ... \\
...    & ...    & ...    & ...    & ...   & ...   & ...     & ...   & ...     & ... \\
...     & ...   & ...   & ...   & ...   & ...   & ...     & ...   & ...     & ... \\
...    & ...    & ...    & ...    & ...   & ...   & ...     & ...  & ...     & ...  \\
...     & ...   & ...   & ...   & ...   & ...   & ...     & ...   & ...     & ... \\
...    & ...    & ...    & ...    & ...   & ...  & ... & ... & ...     & ... \\
\midrule
\multicolumn{10}{|c|}{long long note)} \\
\bottomrule
\end{tabular}
\label{tab:addlabel}
\end{table}

The table should look like this The table should look like this

But instead it comes out like this

Please help me solve this mystery!

3

A solution based on makecell, which allows for line breaks in table cells:

\documentclass{article}
\usepackage[utf8]{inputenc}
 \usepackage{booktabs}
\usepackage{multirow, makecell, caption}
\usepackage{rotating, graphicx}

\begin{document}

\begin{table}
\setlength{\bigstrutjot}{4pt} % Additional height: 4pt
\settowidth\rotheadsize{long text}
\caption{Add caption}
\begin{tabular}{cccccccccc}
\toprule\addlinespace
\multirowcell{2}{long text \\ long text \\ long text} & \multirowcell{3}{text} & & &
\multicolumn{6}{c}{horizontal long long text} \\[1ex]
\cmidrule(lr){5-10}\addlinespace
 & &\raisebox{3ex}[0pt][0pt]{\rotcell[cc]{text}} &
\raisebox{3ex}[0pt][0pt]{\rotcell[cc]{vertical \\ long text}}& 1 & 2 & 3 & 4 & 5 & 6 \\
\addlinespace
\midrule
… & … & … & … & … & … & … & … & … & … \\
… & … & … & … & … & … & … & … & … & … \\
… & … & … & … & … & … & … & … & … & … \\
… & … & … & … & … & … & … & … & … & … \\
… & … & … & … & … & … & … & … & … & … \\
… & … & … & … & … & … & … & … & … & … \\
… & … & … & … & … & … & … & … & … & … \\
\midrule
\multicolumn{10}{c}{long long note)} \\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

enter image description here

  • Thanks, these improvements helped! Now I have a really nice looking table, I really appreciate your help. – Deramite Jul 29 '16 at 13:10
2

You are using the commmands \toprule, \midrule and \bottomrule from the package booktabs. In the package documentation, in section 4, the author explicitly states:

[...] The rules generated by the new commands are in no way guaranteed to connect with verticals generated by {|} characters in the preamble. This is a feature [...]. You should not use vertical rules in tables, end of story.

So this behavior is intended, as you should not use vertical rules (vertical lines). The reason for this is presented earlier in the same document, where the author gives guidelines for creating professional tables:

  1. Never, ever use vertical rules.
  2. Never use double rules.
  3. Put the units in the column heading (not in the body of the table).
  4. Always precede a decimal point by a digit; thus 0.1 not just .1
  5. Do not use `ditto' signs or any other such convention to repeat a previous value. In many circumstances a blank will serve just as well. If it won't, then repeat the value

Then, you have a problem with the combination of multirow and sideways. You can tweak this manually, by adding \bigstrut to both header rows, which enlarges their size. I chose an additional height of 4pt, which looks quite good in my opinion. Then, by putting the text inside a \parbox of e.g. 1.5cm width, you make sure this text is not wider than this.

Together, this gives a quite pleasing result:

result

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow,bigstrut}
\usepackage{rotating}

\begin{document}

\setlength{\bigstrutjot}{4pt}    % Additional height: 4pt

\begin{tabular}{cccccccccc}
\toprule\bigstrut
\multirow{2}{*}{long text} & \multirow{2}[4]{*}{text} & 
\multirow{2}{*}[-1ex]{\begin{sideways}text\end{sideways}} & 
\multirow{2}{*}[1ex]{\begin{sideways}\parbox{1.5cm}{vertical long text}\end{sideways}} &
\multicolumn{6}{c}{long text} \\ 
\cmidrule{5-10}\bigstrut          &       &       &       & 1    & 2    & 3     & 4    & 5     & 6 \\
\midrule
...    & ...    & ...    & ...    & ...   & ...   & ...    & ...   & ...     & ...  \\
...    & ...    & ...    & ...    & ...   & ...   & ...     & ...  & ...     & ... \\
...    & ...    & ...    & ...    & ...   & ...   & ...     & ...   & ...     & ... \\
...     & ...   & ...   & ...   & ...   & ...   & ...     & ...   & ...     & ... \\
...    & ...    & ...    & ...    & ...   & ...   & ...     & ...  & ...     & ...  \\
...     & ...   & ...   & ...   & ...   & ...   & ...     & ...   & ...     & ... \\
...    & ...    & ...    & ...    & ...   & ...  & ... & ... & ...     & ... \\
\midrule
\multicolumn{10}{c}{long long note)} \\
\bottomrule
\end{tabular}

\end{document}
  • Thanks, that really looks much better. I had to change few parameters to match the length of the text to match my table. But it still leaves me few things I would like to change: First column spreads out a lot and does not seem to wrap, if I use p{2cm} parameter; Second is that vertical long text is not centered. Do you have any suggestions regarding that? – Deramite Jul 29 '16 at 10:15
  • @Deramite see the answer by Bernard below, this solves these problems nicely. – hbaderts Jul 29 '16 at 11:54
1

This is quite straightforward using ConTeXt natural tables.

\setupcaption[table][location=top]

\starttext

\placetable[tab:addlabel]{Add caption}{
  \startTABLE[align={middle,lohi}]
    \NC[ny=2] long text \NC[ny=2] text \NC[ny=2] \rotate[90]{text} \NC[ny=2] \rotate[90]{vertical long text} \NC[nx=6] long text \NC\NR
    \NC 1 \NC 2 \NC 3 \NC 4 \NC 5 \NC 6 \NC\NR
    \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC\NR
    \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC\NR
    \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC\NR
    \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC\NR
    \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC\NR
    \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC\NR
    \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC ... \NC\NR
    \NC[nx=10] long long note \NC\NR
  \stopTABLE
}

\stoptext

enter image description here

  • Thanks, but it seemed a bit too difficult since I use tabular most of the time. – Deramite Jul 29 '16 at 10:18

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.