2

I have a table and I want to have vertical centered text. But somehow my text in the table is not centered. Could you help me to center my vertical text?


% page setup 
\documentclass[a4paper, 11pt]{article}
\usepackage[left=2cm,top=2cm,right=2cm, bottom=2cm]{geometry}

\usepackage[utf8]{inputenc} 
\usepackage[english]{babel} 

\usepackage{amsmath} 
\usepackage{amssymb} 
\usepackage{amsthm}  

\usepackage{ragged2e} 
\usepackage{booktabs, tabularx} 
\usepackage{array,multirow,graphicx} 
\newcolumntype{C}{>{\small\raggedright\arraybackslash}X}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}
\newlength\colwidth


\begin{document}

\begin{table}

\small
\settowidth\colwidth{SEThh} % set width of 1st col.
\begin{tabularx}{\textwidth}{@{}P{\colwidth}* {1}P{\colwidth}  * {5}{C} @{}}
    \toprule
& \textbf{Set}  & \textbf{category A} & \textbf{category B} &\textbf{category C} & \textbf{category D} \\
\midrule
\multirow{8}{*}{\rotatebox[origin=c]{90}{\textbf{Center}}} & 1.1 & Text & text &text&   - \\
\addlinespace
 & 1.1 & text & text &text&   - \\
\addlinespace
 & 1.1 & text & text &text&   - \\
\addlinespace
 & 1.1 & text & text &text&   - \\
\addlinespace
 & 1.1 & text & text &text&   - \\
\addlinespace
 & 1.1 & text & text &text&   - \\
\addlinespace
 & 1.1 & text & text &text&   - \\
 \addlinespace
 & 1.1 & text & text &text&   - \\
    \bottomrule
\end{tabularx}
\endtabularx
\end{table}


\end{document}


3 Answers 3

3

The \addlinespace command adds a space of 0.5 em (\defaultaddspace=.5em). You have seven \addlinespaces which add 3.5 em of extra vertical space to the 8 lines of \multirow. So you need to move the text down about 1.75 em (my calculation is approximate, sorry):

\multirow{8}{*}[-1.75em]{\rotatebox[origin=c]{90}{\textbf{Center}}} 

MWE

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{ragged2e} 
\usepackage{booktabs, tabularx} 
\usepackage{array,multirow,graphicx} 
\newcolumntype{C}{>{\small\raggedright\arraybackslash}X}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}
\newlength\colwidth

\begin{document}
 
 \begin{table}
  \small
  \settowidth\colwidth{SEThh} % set width of 1st col.
  \begin{tabularx}{\textwidth}{@{}P{\colwidth}*{1}P{\colwidth}*{5}{C}@{}}
  \toprule
   & \textbf{Set}  & \textbf{category A} & \textbf{category B} &\textbf{category C} & \textbf{category D} \\
   \midrule
   \multirow{8}{*}[-1.75em]{\rotatebox[origin=c]{90}{\textbf{Center}}} 
   & 1.1 & Text & text &text&   - \\
   \addlinespace
   & 1.1 & text & text &text&   - \\
   \addlinespace
   & 1.1 & text & text &text&   - \\
   \addlinespace
   & 1.1 & text & text &text&   - \\
   \addlinespace
   & 1.1 & text & text &text&   - \\
   \addlinespace
   & 1.1 & text & text &text&   - \\
   \addlinespace
   & 1.1 & text & text &text&   - \\
   \addlinespace
   & 1.1 & text & text &text&   - \\
   \bottomrule
  \end{tabularx}
  \endtabularx
 \end{table}
 
\end{document}

enter image description here

1
  • amazing! Thank you
    – Elia
    Mar 22, 2021 at 21:12
3

Same reasoning, and we have to take into account the \aboverulesep and belowrulesep of the rules. By trial and error the correct value to lower the text seems to be quite close to 1.9em:

\documentclass[a4paper, 11pt]{article}
\usepackage[left=2cm,top=2cm,right=2cm, bottom=2cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\usepackage{ragged2e}
\usepackage{booktabs, tabularx}
\usepackage{array,multirow,graphicx}
\newcolumntype{C}{>{\small\raggedright\arraybackslash}X}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}
\newlength\colwidth


\begin{document}

\begin{table}

\small
\settowidth\colwidth{SEThh} % set width of 1st col.
\begin{tabularx}{\textwidth}{@{}P{\colwidth}* {1}P{\colwidth} * {5}{C} @{}}
    \toprule
& \textbf{Set} & \textbf{category A} & \textbf{category B} &\textbf{category C} & \textbf{category D} \\
\midrule
\multirow{8}{*}[-1.9em]{\rotatebox[origin=c]{90}{\textbf{Center}}} & 1.1 & Text & text &text& - \\
\addlinespace
 & 1.1 & text & text &text& - \\
\addlinespace
 & 1.1 & text & text &text& - \\
\addlinespace
 & 1.1 & text & text &text& - \\
\addlinespace
 & 1.1 & text & text &text& - \\
\addlinespace
 & 1.1 & text & text &text& - \\
\addlinespace
 & 1.1 & text & text &text& - \\
 \addlinespace
 & 1.1 & text & text &text& - \\
    \bottomrule
\end{tabularx}
\endtabularx
\end{table}

\end{document}

enter image description here

1

Text in your table is already vertical centered, so it is not entirely clear what the problem is. Vertical centering of rotated text in the first column? For it I would use \rothead from the makecell package:

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage[english]{babel}

\usepackage{amsmath, amssymb, amsthm}  % not used in this MWE
\usepackage{rotating}

\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{C}{>{\small\raggedright\arraybackslash}X}


\begin{document}

\begin{table}
    \settowidth\rotheadsize{ Center } 
    \setcellgapes{2pt}
    \makegapedcells
\begin{tabularx}{\linewidth}{@{} c c  * {5}{C} @{}}
    \toprule
    & \textbf{Set}  
        & \textbf{category A} 
            & \textbf{category B} 
                &\textbf{category C} 
                    & \textbf{category D}       \\
    \midrule
\multirow{9.5}{*}{\rothead{\textbf{Center}}} 
    & 1.1 & Text & text &text&   - \\
    & 1.1 & text & text &text&   - \\
    & 1.1 & text & text &text&   - \\
    & 1.1 & text & text &text&   - \\
    & 1.1 & text & text &text&   - \\
    & 1.1 & text & text &text&   - \\
    & 1.1 & text & text &text&   - \\
    & 1.1 & text & text &text&   - \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

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