如何将文本放置在每个单元格的中心(垂直和水平)?

如何将文本放置在每个单元格的中心(垂直和水平)?

这是屏幕截图和源代码。

表格图片

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage{amssymb}
\usepackage{array, boldline, rotating}

\newcommand{\thickhline}{\hlineB{4}}

\begin{document}

\begin{table} [h]
\centering
\begin{tabular}{p{3.50cm}V{4}*{6}{p{0.85cm}|}}
% \multirow{1}{*} {\textbf{Authors}} & & & & & & & & \textbf{Context and use of RSS} \\ &
   
{Category }& 
\rotatebox{90}{Student 345} &
\rotatebox{90}{Student 4} &
\rotatebox{90}{Student 4} &
\rotatebox{90}{Student 4} &
    
\rotatebox{90}{Student 6} &
\rotatebox{90}{Student 9} \\
\thickhline
Student 3 & & & & & & \\[0.3cm]
 
\hline
Student 3 & & & & & & \\[0.3cm]
\hline
Student 3 & & & & & & \\[0.3cm]
\hline
Student 3 & & & & & & \\[0.3cm]
\hline
Student 4 & \checkmark & & & & &\\[0.3cm]
\hline
Student 6 & \checkmark & \checkmark & && & \\[0.3cm]
\hline
Student 9 & \checkmark & \checkmark & \checkmark && & \\[0.3cm]
\thickhline
\end{tabular}
\caption{Averaging of correlations for RSS feed 140.}
\label{tab:CorrelationAveraging}
\end{table}

\end{document} 

答案1

我会用tabularray包裹。

\documentclass{article}
\usepackage{tabularray}
\usepackage{amssymb}
\usepackage{rotating}

\begin{document}

\begin{table}
    \centering
    \begin{tblr}{
        colspec = {p{3.50cm}*{6}{p{0.85cm}}},
        hlines, vlines, %create all horizontal and vertical lines
        hline{1} = {0pt}, %vanish the 1st horizontal line
        hline{2, Z} = {2pt}, %thicken the 2nd and the last horizontal line
        vline{1} = {0pt}, %vanish the 1st vertical line
        vline{2} = {2pt}, %thicken the 2nd vertical line
        cells = {c, m}, %make all cells horizontally and vertically centered
        cell{1}{1} = {f}, %but align the very 1st cell to the bottom
        cell{1}{2-Z} = {cmd=\rotatebox{90}}, % rotate all but the 1st columns of the 1st row
        row{2-Z} = {0.6cm} %set the height of all but the 1st rows
    }
        Category & 
        Student 345 & Student 4 & Student 4 & Student 4 & Student 6 & Student 9 \\
        Student 3 & & & & & & \\
        
        Student 3 & & & & & & \\
        
        Student 3 & & & & & & \\
        
        Student 3 & & & & & & \\
        
        Student 4 & \checkmark & & & & &\\
        
        Student 6 & \checkmark & \checkmark & && & \\
        
        Student 9 & \checkmark & \checkmark & \checkmark && & \\
    \end{tblr}
    \caption{Averaging of correlations for RSS feed 140.}
    \label{tab:CorrelationAveraging}
\end{table}

\end{document}

在此处输入图片描述

答案2

采用相对较新的tabularray包装:

\documentclass{article}
\usepackage{dingbat}
\newcommand\cm{\checkmark} % TealCheckMark

\usepackage{rotating}
\usepackage{makecell}
\usepackage{tabularray}

\begin{document}
    \begin{table} [h]
\settowidth\rotheadsize{Student 345}
\centering
\begin{tblr}{hline{2,Z} = 1pt, hline{3-Y},
             vline{2} = {1pt}, vline{3-Z},
             colspec  = {*{7}{Q[c] }},
             cell{1}{1} = {f},
             cell{1}{2-Z} = {cmd=\rotcell}
            }
Category    & Student 345   & Student 4 & Student 4
            & Student 4     & Student 6 & Student 9 \\
Student 3   &       &       &       &   &   &       \\
Student 3   &       &       &       &   &   &       \\
Student 3   &       &       &       &   &   &       \\
Student 3   &       &       &       &   &   &       \\
Student 4   & \cm   &       &       &   &   &       \\
Student 6   & \cm   & \cm   &       &   &   &       \\
Student 9   & \cm   & \cm   & \cm   &   &   &       \\
\end{tblr}
\caption{Averaging of correlations for RSS feed 140.}
\label{tab:CorrelationAveraging}
    \end{table}
\end{document}

在此处输入图片描述

答案3

您可以使用cellspace包来完成此操作,该包使您能够在默认情况下以字母为前缀的说明符的列中定义单元格顶部和底部的最小垂直间距S(或者C如果您加载siunitx,或使用加载时间选项的任何字母):

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{amssymb}
    \usepackage{array, boldline, rotating}
    \usepackage{cellspace}
    \setlength{\cellspacetoplimit}{2.5ex}
    \setlength{\cellspacebottomlimit}{2ex}
    \newcommand{\thickhline}{\hlineB{4}}

    \begin{document}


    \begin{table} [h]
    \centering
    \begin{tabular}{S{wc{3.50cm}}V{4}*{6}{wc{0.85cm}|}}
    % \multirow{1}{*} {\textbf{Authors}} & & & & & & & & \textbf{Context and use of RSS} \\ &

    {Category }&
    \rotatebox{90}{Student 345} &
    \rotatebox{90}{Student 4} &
    \rotatebox{90}{Student 4} &
    \rotatebox{90}{Student 4} &

    \rotatebox{90}{Student 6} &
    \rotatebox{90}{Student 9} \\
    \thickhline
    Student 3 & & & & & & \\[0.3cm]

    \hline
    Student 3 & & & & & & \\[0.3cm]
    \hline
    Student 3 & & & & & & \\[0.3cm]
    \hline
    Student 3 & & & & & & \\[0.3cm]
    \hline
    Student 4 & \checkmark & & & & &\\[0.3cm]
    \hline
    Student 6 & \checkmark & \checkmark & && & \\[0.3cm]
    \hline
    Student 9 & \checkmark & \checkmark & \checkmark && & \\[0.3cm]
    \thickhline
    \end{tabular}
    \caption{Averaging of correlations for RSS feed 140.}
    \label{tab:CorrelationAveraging}
    \end{table}

    \end{document} 

在此处输入图片描述

答案4

一些建议:

  • >{\centering\arraybackslash}在每个列类型前面加上前缀p,以获得水平居中

  • \arraystretch通过设置一个适当大的数字(例如),来改变增加单元格高度的方式2.0

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage{amssymb, array, boldline, graphicx}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcommand{\thickhline}{\hlineB{4}}

\begin{document}

\begin{table} [h]
\renewcommand\arraystretch{2}
\centering
\begin{tabular}{P{2.5cm} V{4} *{6}{P{0.85cm}|} }
   
Category & 
\rotatebox{90}{Student 345} &
\rotatebox{90}{Student 4}   &
\rotatebox{90}{Student 4}   &
\rotatebox{90}{Student 4}   &
\rotatebox{90}{Student 6}   &
\rotatebox{90}{Student 9}   \\
\thickhline
Student 3 & & & & & & \\
\hline
Student 3 & & & & & & \\
\hline
Student 3 & & & & & & \\
\hline
Student 3 & & & & & & \\
\hline
Student 4 & \checkmark & & & & & \\
\hline
Student 6 & \checkmark & \checkmark & && & \\
\hline
Student 9 & \checkmark & \checkmark & \checkmark && & \\
\thickhline
\end{tabular}
\caption{Averaging of correlations for RSS feed 140.}
\label{tab:CorrelationAveraging}
\end{table}

\end{document}

相关内容