如何使旋转框表格单元格居中?

如何使旋转框表格单元格居中?

我已经创建了一个表格,并且固定了它的宽度,但问题是,当我使用 旋转单元格的文本时\rotatebox,文本没有放置在单元格的中心。我该如何改变它的位置?我的表格:

\documentclass{article}
\usepackage[utf8]{inputenc}


\usepackage{natbib}
\usepackage{graphicx}
\usepackage{amsmath}

\begin{document}









\begin{center}
\begin{table*}[htp]
%\scriptsize        
\centering
%\begin{tabular}{|l|l|l|l|l|l|l|l|l|}


\begin{tabular} {|p{0.04\textwidth}|p{0.04\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.02\textwidth}|} 
\hline


Text text text text
&

Text text text text
&

Text text text text
& 

Text text text text
& 

Text text text text
\\ \hline

{\multirow [c]{2}{*}{\rotatebox{90}{ {Example 1} }}}  & 
%[origin=c]
{\multirow [c]{3}{*}{\rotatebox{90}{ Example 2 }}}


 & 

Text text text text
& 
Text text text text
& 

%\begin{tabular} {@{}l@{}}
%\begin{tabular}[c]{@{}l@{}}
 
Text text text text

Text text text text
%\end{tabular}


 & 
 
 

%\begin{tabular}{@{}l@{}}

Text text text text
Text text text text
Text text text text

%\end{tabular}  

  & 
Text text text text
Text text text text
Text text text text
Text text text text
& 
Text text text text

& r1 \\ \cline{3-9}&  & 

Text text text text
& 
Text text text text
& 
 
 
 
 %\begin{tabular}{@{}l@{}}


Text text text text
Text text text text
%\end{tabular}

& 

Text text text text
&

Text text text text& 

Text text text text
& 

r2 \\ 


\cline{1-1} \cline{3-9} 

{\rotatebox[origin=c]{90}{ Feedback }}  &  
&
Text text text text

 &
Text text text text
& 
Text text text text

& 
Text text text text

& Text text text text

& 
%\multicolumn{1}{c|}{
//
%} 
& 

r3 

\\ 
\hline

{\rotatebox[origin=c]{90}{   Example 3    }} & 

{\rotatebox[origin=c]{90}{ Example 4 }} 
& 
Text text text text
&
Text text text text
& 
%\begin{tabular} {@{}l@{}}
Text text text text
 Cost. 
%\end{tabular}
&
Text text text text
& 
Text text text text
& 
Text text text text

& 


r4 

\\ \hline

\end{tabular}

\end{table*}
\end{center}
\end{document}

我想要更改单元格中心的单词 example1 和 example2 的替换。在此处输入图片描述

答案1

像这样?

在此处输入图片描述

\multirow命令中,您需要设置行中文本行的数量,这些行由它跨越。例如,“示例 1”跨越 12 个文本行,因此

{\multirow [c]{2}{*}{\rotatebox{90}{ {Example 1} }}}

你应该写

\multirow{12}{*}{\rotatebox{90}{Example 1}}

该表适合\textwidth我建议使用tabularx表环境。完整的 MWE 是:

\documentclass{article}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{ragged2e}
\usepackage{multirow, tabularx}


\begin{document}
    \begin{table}[htp]
\small
\centering
\begin{tabularx} {\linewidth} {|p{0.04\textwidth}|p{0.04\textwidth}|*{6}{>{\RaggedRight}X|}l|}
    \hline
Text text text text
& Text text text text
& Text text text text
& Text text text text
& Text text text text
&&&&    \\ \hline
\multirow{12}{*}{\rotatebox{90}{Example 1}}
& \multirow{16}{*}{\rotatebox{90}{Example 2}}
& Text text text text
& Text text text text
& Text text text text Text text text text
& Text text text text Text text text text Text text text text
& Text text text text Text text text text Text text text text Text text text text
& Text text text text
& r1 \\ \cline{3-9}
&  & Text text text text
& Text text text text
& Text text text text Text text text text
& Text text text text
& Text text text text
& Text text text text
& r2 \\ \cline{1-1} \cline{3-9}
\multirow{4.4}{*}{\rotatebox{90}{Feedback}}
&   &   &   &   &   &   &   &       \\
&   & Text text text text
& Text text text text
& Text text text text
& Text text text text
& Text text text text
&   & r3    \\
&   &   &   &   &   &   &   &       \\
    \hline
\multirow{5}{*}{\rotatebox{90}{Example 3}}
& \multirow{5}{*}{\rotatebox{90}{Example 4}}
&   &   &   &   &   &   &         \\
&
& Text text text text
& Text text text text
& Text text text text Cost.
& Text text text text
& Text text text text
& Text text text text
& r4    \\
&   &   &   &   &   &   &   &       \\
    \hline
\end{tabularx}
    \end{table}
\end{document}

答案2

{NiceTabular}在 (≥ 4.1)的环境中nicematrix,您可以使用命令\Block以数学方式将其内容置于合并单元格的中心(您不必计算文本行)。此外,您还可以使用关键字\rotate来旋转块的内容。

你还有一把钥匙hvlines,可以绘制所有的规则除外(因此,您不必使用\cline)。

\documentclass{article}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{nicematrix}


\begin{document}
\begin{table}[htp]
\small
\centering
\NiceMatrixOptions{cell-space-top-limit=2pt,cell-space-bottom-limit=2pt}
\newcolumntype{P}[1]{>{\raggedright}p{#1\textwidth}}
\begin{NiceTabular}{P{0.04}P{0.04}P{0.12}P{0.12}P{0.12}P{0.12}P{0.12}P{0.12}C}[hvlines]
Text text text text
& Text text text text
& Text text text text
& Text text text text
& Text text text text
& & & & \\
\Block{2-1}{\rotate Example 1}
& \Block{3-1}{\rotate Example 2}
& Text text text text
& Text text text text
& Text text text text Text text text text
& Text text text text Text text text text Text text text text
& Text text text text Text text text text Text text text text Text text text text
& Text text text text
& r1 \\ 
&  
& Text text text text
& Text text text text
& Text text text text Text text text text
& Text text text text
& Text text text text
& Text text text text
& r2 \\ 
\multicolumn{1}{C}{\rotatebox[origin=b]{90}{Feedback\vphantom{p}}}
&   & Text text text text
& Text text text text
& Text text text text
& Text text text text
& Text text text text
&   & r3    \\
\multicolumn{1}{C}{\rotatebox[origin=b]{90}{Example 3}}
& \multicolumn{1}{C}{\rotatebox[origin=b]{90}{Example 4}}
& Text text text text
& Text text text text
& Text text text text Cost.
& Text text text text
& Text text text text
& Text text text text
& r4    \\
\end{NiceTabular}
\end{table}
\end{document}

上述代码的输出

答案3

对我来说,一种更简单的方法是添加空格来手动使文本居中(\hspace{XXcm}):

\multirow{12}{*}{ \rotatebox[origin=c]{90} {Example 1 \hspace{1cm} } }

相关内容