LaTeX tables / vertical alignment / spacing

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 LaTeX tables / vertical alignment / spacing

LaTeX tables / vertical alignment / spacing

But instead it comes out like this

Please help me solve this mystery!

Replay

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}

LaTeX tables / vertical alignment / spacing

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:

LaTeX tables / vertical alignment / spacing

\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}

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

LaTeX tables / vertical alignment / spacing

Category: tables Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.305 (s). 12 q(s)