latexmultirow

How to vertically center text in multirow in table


I am trying to vertically center the test in the first column which is a multirow of the table. The code is as follows:

\begin{table}[]
\tiny
\caption{a}

\begin{tabular}{|M{0.1in}|p{0.7in}|p{1.4in}|p{2in}|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
   & \textbf{Factor Name} & \textbf{Explanation} & \textbf{Rationale} \\
  \hline
  \multirow{4}{*}{\rotatebox[origin=c]{90}{test}}& body1 &body2 &\multirow{2}{*}{\parbox{2in}{body3}}  \\
  \hhline{~--~}
   & 1 & 2 \newline & \\
     \hhline{~---}
   & 3& 3 & \multirow{2}{*}{5}  \\
     \hhline{~--~}
   & 6 & 7 & \\
   \hhline{----}

  
   \hline
\end{tabular}
\end{table}

Any idea to do this?


Solution

  • test should span 5 rows, not 4; the row containing 1 and 2 spans two lines for which you should accommodate in your \multirow statement:

    enter image description here

    \documentclass{article}
    
    \usepackage{multirow,hhline,graphicx,array}
    \newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
    
    \begin{document}
    
    \begin{tabular}{|M{0.1in}|p{0.7in}|p{1.4in}|p{2in}|}
      \hline
      % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
       & \textbf{Factor Name} & \textbf{Explanation} & \textbf{Rationale} \\
      \hline
      \multirow{5}{*}{\rotatebox[origin=c]{90}{test}}& body1 &body2 &\multirow{2}{*}{\parbox{2in}{body3}} \\
      \hhline{~--~}
       & 1 & 2 \newline & \\
       \hhline{~---}
       & 3 & 3 & \multirow{2}{*}{5} \\
       \hhline{~--~}
       & 6 & 7 & \\
       \hhline{----}
    \end{tabular}
    
    \end{document}