1

I've been two days trying to add top and bottom margins to some cells in my latex table (the ones that have the more text). I couldn't find a solution. This is the code I have.

\documentclass{article}
\usepackage[landscape,margin=2cm]{geometry}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{tabu}
\newcommand\xrowht[2][0]{\addstackgap[.5\dimexpr#2\relax]{\vphantom{#1}}}

\begin{document}
\begin{table}
\centering
\begin{tabu}{|X[2]|X[10]|X[2]|X[7]|X|
X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|}
\hline
\rotatebox{90}{Id. number 1} & 
     number 1 & 
     \rotatebox{90}{Id. n2} & 
     number 2& 
     \rotatebox{90}{Esfuerzo p-d} & 
     \rotatebox{90}{Día 1} & 
     \rotatebox{90}{Día 2} & 
     \rotatebox{90}{Día 3} & 
     \rotatebox{90}{Día 4} & 
     \rotatebox{90}{Día 5} & 
     \rotatebox{90}{Día 6} & 
     \rotatebox{90}{Día 7} & 
     \rotatebox{90}{Día 8} & 
     \rotatebox{90}{Día 9} & 
     \rotatebox{90}{Día 10} & 
     \rotatebox{90}{Día 11} & 
     \rotatebox{90}{Día 12} & 
     \rotatebox{90}{Día 13} & 
     \rotatebox{90}{Día 14} & 
     \rotatebox{90}{Día 15}\\ 
     \hline
     \multirow[c]{6}{=}{COM-HU01} &
     \multirow[c]{6}{=}{This is a cell with a lot of information that have to be in a paragraph style in the table} &
    01-01 & Do some things also in a semi-pharagraph style &
    2 & & & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ \cline{3-20}
 & & 01-02 & Some other things
    & 2 &  & 1 &  & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \cline{3-20} 
 & & 01-03 & To do number three
    & 3 & & & & & & & & 1 & 2 & 0 & 0 & 0 & 0 & 0 & 0 \\ \cline{3-20} 
 & & 01-04 & To do number four
    & 1 & & & & & & & & & & & & & & &   \\ \cline{3-20} 
 & & 01-05 & To do number five
    & 2 & & & & & & & & & & & & & & & \\ \cline{3-20} 
 & & 01-06 & Another semi pharagraph style cell 
    & 3 & & & & & & & & 1 & & & & & & & \\ \hline
\end{tabu}
\end{table}
\end{document}

Thank you in advance. PD: I would also appreciate if there's any way to vertically center all the cells

8
  • Welcome to TeX.SX! Could you please make your code compilable by adding the documentclass as well as the relevant package? Could you please also clarify what "top and bottom margins" refers to? Do you want to add some vertical white space between teh text and the surrounding borders of the cells?
    – leandriis
    Commented Mar 6, 2020 at 21:33
  • Welcome to tex.sx! Are you set on using tabu? Or could you live with using another tabular environment?
    – TivV
    Commented Mar 6, 2020 at 21:34
  • @TivV: I'd guess the vertical alignment issue in this particular case is more related to the use of multirow.
    – leandriis
    Commented Mar 6, 2020 at 21:35
  • @leandriis, Hi, thank you for helping me. Some cells are just too tight between the top line and the text, and between the bottom line and the text, yes Commented Mar 6, 2020 at 21:56
  • @VioletaGarcía: Thanks for the edit and the clarification. Could you please also add the document class you are currently using?
    – leandriis
    Commented Mar 6, 2020 at 22:07

1 Answer 1

2

Here is my suggestion building upon tabularx for the X type colums, makecell for the rotated column headers, cellspace for the additional white space between text and horizontal line, \newcolumntype{L}{>{\raggedright\arraybackslash}X} to left align the contents of the newly defined L type columns and \renewcommand\tabularxcolumn[1]{m{#1}} to vertically center the contents:

enter image description here

\documentclass{article}
\usepackage[landscape,margin=2cm]{geometry}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{rotating}
\usepackage{tabularx}
\usepackage{cellspace}
\addparagraphcolumntypes{X}
\setlength\cellspacetoplimit{10pt}
\setlength\cellspacebottomlimit{\cellspacetoplimit}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}

\begin{table}
    \settowidth\rotheadsize{\theadfont Id. number 1}
    \renewcommand\cellrotangle{90}
\begin{tabularx}{\textwidth}{|S{c}|S{L}|S{c}|L|*{16}{S{c}|}}
\hline
\rothead{Id. number 1} & 
     number 1 & 
     \rothead{Id. n2} & 
     number 2& 
     \rothead{Esfuerzo p-d} & 
     \rothead{Día 1} & 
     \rothead{Día 2} & 
     \rothead{Día 3} & 
     \rothead{Día 4} & 
     \rothead{Día 5} & 
     \rothead{Día 6} & 
     \rothead{Día 7} & 
     \rothead{Día 8} & 
     \rothead{Día 9} & 
     \rothead{Día 10} & 
     \rothead{Día 11} & 
     \rothead{Día 12} & 
     \rothead{Día 13} & 
     \rothead{Día 14} & 
     \rothead{Día 15}\\ 
     \hline
     \multirow[c]{12.5}{*}{\makecell{COM-\\HU01}} &
     \multirow[c]{12.5}{=}{This is a cell with a lot of information that have to be in a paragraph style in the table} &
    01-01 & Do some things also in a semi-pharagraph style &
    2 & & & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ \cline{3-20}
 & & 01-02 & Some other things
    & 2 &  & 1 &  & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \cline{3-20} 
 & & 01-03 & To do number three
    & 3 & & & & & & & & 1 & 2 & 0 & 0 & 0 & 0 & 0 & 0 \\ \cline{3-20} 
 & & 01-04 & To do number four
    & 1 & & & & & & & & & & & & & & &   \\ \cline{3-20} 
 & & 01-05 & To do number five
    & 2 & & & & & & & & & & & & & & & \\ \cline{3-20} 
 & & 01-06 & Another semi pharagraph style cell 
    & 3 & & & & & & & & 1 & & & & & & & \\ \hline
\end{tabularx}
\end{table}
\end{document}
2
  • Seriously, I've been looking for this two entire days and you solved it in half an hour. Thank you so much Commented Mar 6, 2020 at 23:04
  • @VioletaGarcía: You're welcome. If you need some explanation on the code I used, please don't hesitate to ask.
    – leandriis
    Commented Mar 7, 2020 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .