1

I have created simple table which purposefully has all cells, except first row and first column, blank.

\documentclass{book}
\usepackage{rotating}
\linespread{1.2}
\begin{document}
\thispagestyle{empty}
\begin{sideways}
\bgroup
\def\arraystretch{1.5}
\setlength\tabcolsep{10pt}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 & Column 4 & Column 5 & Column 6 & Column 7 & Column 8 & Column 9 & Column 10 & Column 11 \\
\hline
Row 2 & & & & & & & & & & \\
\hline
Row 3 & & & & & & & & & & \\
\hline
Row 4 & & & & & & & & & & \\
\hline
Row 5 & & & & & & & & & & \\
\hline
Row 6 & & & & & & & & & & \\
\hline
\end{tabular}
\egroup
\end{sideways}
\thispagestyle{empty}
\end{document}

As you can see, I have made three important changes: \linespread{1.2} for linespacing for the rest of the document (not relevant for MWE), \def\arraystretch{1.5} for vertical padding inside cells and \setlength\tabcolsep{10pt} for horizontal padding inside cells.

I want to have text in the cells to be centered both vertically and horizontally. Without those three commands above, it seems to happen. However, once I add those three commands for better presentation, they seem to move text in the cells below vertical center. Examples:

enter image description here enter image description here

Is there any way to keep those spacing/padding adjustments, but at the same time make text in the cell centered both vertically and horizontally? Also, why code of MWE creates PDF with two pages, instead of one?

3

Two solutions for vertical centring of cell contents:

  • The makecell package has commands for vertical padding of cell: \setcellgapes to define a value for the padding (in preamble), and \makegapedcells to use is in a given environment.
  • The cellspace package works differently: it defines minimal vertical spacings between a cell and the above and below cells: \cellspacetoplimit and cellspacebottomlimit. You have to prefix the corresponding column specifier with the letter S (or C if you use the siunitx package).

Here is a code for both ways:

\documentclass{book}
\usepackage[margin=2cm]{geometry}
\usepackage{rotating}
\usepackage{array, makecell}
\setcellgapes{7.5pt}
\usepackage{cellspace}
\setlength\cellspacetoplimit{7.5pt}
\setlength\cellspacebottomlimit{7.5pt}
\linespread{1.2}

\begin{document}

\pagestyle{empty}
\begin{sideways}
  \bgroup
  \makegapedcells
  \setlength\tabcolsep{10pt}
  \begin{tabular}{|*{11}{c|}}
    \multicolumn{11}{l}{\texttt{With makecell: }}\\[2ex]
    \hline
    Column 1 & Column 2 & Column 3 & Column 4 & Column 5 & Column 6 & Column 7 & Column 8 & Column 9 & Column 10 & Column 11 \\
    \hline
    Row 2 & & & & & & & & & & \\
    \hline
    Row 3 & & & & & & & & & & \\
    \hline
    Row 4 & & & & & & & & & & \\
    \hline
    Row 5 & & & & & & & & & & \\
    \hline
    Row 6 & & & & & & & & & & \\
    \hline
  \end{tabular}
  \egroup
\end{sideways}
\hskip1cm
\begin{sideways}
  \bgroup
  \setlength\tabcolsep{10pt}
  \begin{tabular}{|*{11}{Sc|}}
    \multicolumn{11}{c}{\texttt{With cellspace: }}\\[2ex]
    \hline
    Column 1 & Column 2 & Column 3 & Column 4 & Column 5 & Column 6 & Column 7 & Column 8 & Column 9 & Column 10 & Column 11 \\
    \hline
    Row 2 & & & & & & & & & & \\
    \hline
    Row 3 & & & & & & & & & & \\
    \hline
    Row 4 & & & & & & & & & & \\
    \hline
    Row 5 & & & & & & & & & & \\
    \hline
    Row 6 & & & & & & & & & & \\
    \hline
  \end{tabular}
  \egroup
\end{sideways}

\end{document} 

enter image description here

1

The second page appears because your table is too big. You have to reduce this somehow. Your problem was addressed several times before. Please read Vertical alignment problem with \arraystretch and m column definition, Make \addlinespace globally to work with all tables, and https://tex.stackexchange.com/a/50337.

Maybe you would be better served with a tabu or tabularx here. The latter would make your \setlength\tabcolsep unnecessary.

I would do the following:

% arara: pdflatex

\documentclass{book}
\usepackage{showframe} % for demo
\usepackage{booktabs}
\usepackage{rotating}

\begin{document}
\begin{sidewaystable}
    \footnotesize % smaller font in order to fit the table on the page
    \centering
    \setlength\tabcolsep{6.4pt} % this is the maximum in order to fit on the page
    \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{*{11}{l}}
        \toprule
        Column 1 & Column 2 & Column 3 & Column 4 & Column 5 & Column 6 & Column 7 & Column 8 & Column 9 & Column 10 & Column 11 \\\addlinespace[2pt]
        \midrule
        Row 2 & & & & & & & & & & \\
        Row 3 & & & & & & & & & & \\
        Row 4 & & & & & & & & & & \\
        Row 5 & & & & & & & & & & \\
        Row 6 & & & & & & & & & & \\\addlinespace[2pt]
        \bottomrule
    \end{tabular}
\end{sidewaystable}
\end{document}

enter image description here


A tabu solution could be:

% arara: pdflatex

\documentclass{book}
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{rotating}

\begin{document}
\begin{sidewaystable}
    \tabulinesep = 3mm
    \footnotesize % smaller font in order to fit the table on the page
    \begin{tabu} to \textwidth {*{11}{X@{}}}
        \toprule
        Column 1 & Column 2 & Column 3 & Column 4 & Column 5 & Column 6 & Column 7 & Column 8 & Column 9 & Column 10 & Column 11 \\
        \midrule
        Row 2 & & & & & & & & & & \\
        Row 3 & & & & & & & & & & \\
        Row 4 & & & & & & & & & & \\
        Row 5 & & & & & & & & & & \\
        Row 6 & & & & & & & & & & \\
        \bottomrule
    \end{tabu}
\end{sidewaystable}
\end{document}

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.