单元格中的文本对齐

单元格中的文本对齐

对于此表,我如何使文本居中并强制它适合第三列的单元格大小,以及如何使第一行中的列之间出现线条。

\begin{table}[h]
        \begin{center}
        \scriptsize
        \label{1}
        \scriptsize
        \renewcommand{\arraystretch}{1.4}
        
             \begin{tabular}{|m{0.5\textwidth}|  % <-- use 'm', not 'p', col. type
                         m{0.2\textwidth}|  
                          m{0.2\textwidth}|                     
                       }
                                      \hline
            \rowcolor{Black}
            \textcolor{white}{Criteria} $^\star$ &  \textcolor{white}{Moderators Assessment} & \textcolor{white}{Response by Assessment Author, Including Actions Taken}\\ \hline
            \hline                          
        \end{tabular}
        \end{center} 
\end{table}

答案1

不太清楚您想如何设计您的表格。我猜您可能有类似这样的内容:

在此处输入图片描述

\documentclass[10pt,a4paper]{article}
\usepackage[table, svgnames]{xcolor}
\usepackage{ragged2e}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\newcolumntype{Y}[1]{>{\hsize=#1\linewidth\RaggedRight\hspace{0pt}}X}

\usepackage{lipsum}

\begin{document}
    \begin{table}[h]
    \footnotesize
\caption{My table}
\label{tab:1}
    \centering
    \renewcommand{\arraystretch}{1.4}
\begin{tabularx}{\linewidth}{%
        |Y{0.5} |
         Y{0.2} |
         Y{0.3} |
                }
    \hline
    \rowcolor{Black}
\multicolumn{1}{Y{0.5}!{\color{white}\vrule}}{ \textcolor{white}{Criteria $^\star$}}
    &   \multicolumn{1}{Y{0.2}!{\color{white}\vrule}}{\textcolor{white}{Moderators Assessment}}
        &   \multicolumn{1}{Y{0.3}|}{\textcolor{white}{Response by Assessment Author, Including Acti\-ons Taken}}
        \\
    \hline
\lipsum[66]
    &   qwerty
        &   quertz
        \\  \hline
\end{tabularx}
    \end{table}
\end{document}

答案2

我假设你想要可用的第一列的宽度是其他两列的两倍。如果是这样,我建议使用tabularx而不是tabular。接下来,考虑到列很窄,我将放弃单元格内容的完全对齐,而改用右对齐,同时仍允许连字符。最后,我将在标题行中渲染反转的黑底白字文本大胆的,使其在黑色背景下更易于阅读。哦,我认为在列之间提供垂直线既没有必要,也没有帮助。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,ragged2e,amssymb,lipsum}
\newcolumntype{L}[1]{>{\RaggedRight\hsize=#1\hsize}X}
\usepackage[table,svgnames]{xcolor} % for 'Black' color definition

\begin{document}
\begin{table}
\renewcommand\tabularxcolumn[1]{m{#1}} % cells centered vertically
\scriptsize
\renewcommand{\arraystretch}{1.4}
    % note: 1.5+0.75+0.75 = 3 = # of columns of type X
\begin{tabularx}{\textwidth}{L{1.5} L{0.75} L{0.75}}                 
\rowcolor{Black}
\color{white}\bfseries Criteria$^\star$ &  
\color{white}\bfseries Moderator's Assessment & 
\color{white}\bfseries Response by Assessment Author, including Actions Taken\\ 
\lipsum[1][1-7] & \lipsum[2][1-3] & \lipsum[3][1-3] \\ % filler text
\hline                          
\end{tabularx}
\end{table}
\end{document}

答案3

在此处输入图片描述

\documentclass[10pt,a4paper]{article}
\usepackage[table, svgnames, array]{xcolor}
%\usepackage{}

\begin{document}
    
        \begin{table}[h]
            \begin{center}
                \scriptsize
                \label{1}
                \begin{tabular}{|m{0.5\textwidth}!{\color{green}\vrule} % <-- use 'm', not 'p', col. type
                        m{0.2\textwidth}!{\color{green}\vrule}  
                        m{0.3\textwidth}|                     
                    }
                    \hline
                    \rowcolor{Black}
                    \textcolor{white}{Criteria $^\star$} &  \textcolor{white}{Moderators Assessment} &\textcolor{white}{Response by Assessment Author, Including Actions Taken}\\ \hline
                    \hline                          
                \end{tabular}
            \end{center} 
        \end{table}
\end{document}
\documentclass[10pt,a4paper]{article}
\usepackage[table, svgnames, array]{xcolor}
%\usepackage{color}

\begin{document}
    
        \begin{table}[h]
            \begin{center}
                \scriptsize
                \label{1}
                \scriptsize
                \renewcommand{\arraystretch}{1.4}
                
                \begin{tabular}{|m{0.5\textwidth}!{\color{green}\vrule} % <-- use 'm', not 'p', col. type
                        m{0.2\textwidth}!{\color{green}\vrule}  
                        m{0.3\textwidth}|                     
                    }
                    \hline
                    \rowcolor{Black}
                    \textcolor{white}{Criteria} $^\star$ &  \textcolor{white}{Moderators Assessment} &\textcolor{white}{Response by Assessment Author, Including Actions Taken}\\ \hline
                    \hline                          
                \end{tabular}
            \end{center} 
        \end{table}
\end{document}

相关内容