如何让文本在表格单元格中居中

如何让文本在表格单元格中居中

我怎样才能使该单元格文本居中?

在此处输入图片描述

 \documentclass[12pt]{article}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage[left=1.27cm,right=1.27cm,top=0.7cm,bottom=1.3cm]{geometry}
    \usepackage{fancyhdr}
    \usepackage{array,multirow,makecell}
    \usepackage{colortbl} 
    \usepackage{xcolor}
    \usepackage{here}
    \newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
    \newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
    \newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}
    \pagestyle{fancy}
    
    
    % pour les pieds de page
    \cfoot{ \textsubscript{ Trame du document : FOR\_TEMPLATE }}
    \rfoot{\textsubscript{ \color{red} Ne pas reproduire / Copie contrôlée}}
    \begin{document}
    \begin{table}[!h]
        \centering
        \begin{tabular}{|C{3cm}|L{13.9cm}|}
            \hline
            \rowcolor[RGB]{33,88,104}\multicolumn{2}{|c|}{\textbf{\color{white} Abbreviation }} \\ \hline
            \textbf{Abbreviation} &  \textbf{Meaning} \\ \hline
            COO & Chief Operating Officer   \\ \hline
            RQ \& AR    & Regulatory Affairs and Quality Manager  \\ \hline
            ANSM & Agence Nationale de Sécurité du Médicament et des produits de santé (National drug and medical devices agency) \\ \hline
            CPP & Comité de Protection des Personnes (Ethics Committee) \\ \hline
            CNIL & Commission Nationale Informatique et Liberté (French data protection agency) \\ \hline
            CER & Clinical Evaluation Report \\ \hline 
            IFU &   Instructions For Use \\ \hline
            NC &    Non-conformity \\ \hline
            PMSR &  Post-Market Surveillance Report \\ \hline
            PSUR &  Periodic Safety Update Report  \\ \hline
            CAPA &  Corrective and Preventive Actions \\ \hline
            
        \end{tabular}
    \end{table}
    
    \end{document}

答案1

使用tabularray包装很简单:

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage[hmargin=1.27cm,top=0.7cm,bottom=1.3cm]{geometry}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}
    \begin{table}
\begin{tblr}{hlines, vlines,
             colspec = {Q[l,m] X[l, m]},
              row{1} = {font=\bfseries, bg=teal, fg=white}
              row{2} = {font=\bfseries}
              }
\SetCell[c=2]{c}  Abbreviation
            &                                           \\
Abbreviation    &   Meaning                             \\ 
COO         & Chief Operating Officer                   \\
RQ \& AR    & Regulatory Affairs and Quality Manager    \\
ANSM        & Agence Nationale de Sécurité du Médicament 
et des produits de santé (National drug and medical devices agency) \\
CPP         & Comité de Protection des Personnes (Ethics Committee) \\
CNIL        & Commission Nationale Informatique et Liberté (French data protection agency)  \\
CER         & Clinical Evaluation Report \\
IFU         & Instructions For Use \\
NC          & Non-conformity \\
PMSR        & Post-Market Surveillance Report \\
PSUR        & Periodic Safety Update Report  \\
CAPA        & Corrective and Preventive Actions \\ 
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

但您可能喜欢以下表格设计:

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage[hmargin=1.27cm,top=0.7cm,bottom=1.3cm]{geometry}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
  \ExplSyntaxOn
\NewChildSelector{eachthree}
  {
    \int_step_inline:nnnn {6}{3}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

\begin{document}
    \begin{table}
\begin{tblr}{colspec = {Q[l] X[l]},
              row{1} = {font=\bfseries, bg=teal, fg=white},
              row{2} = {font=\bfseries},
             row{3-Z} = {rowsep=0.5pt},
             row{eachthree} = {abovesep=1.5ex}
             }
\SetCell[c=2]{c}  Abbreviation
            &                                           \\
Abbreviation    &   Meaning                             \\ 
    \midrule
COO         & Chief Operating Officer                   \\
RQ \& AR    & Regulatory Affairs and Quality Manager    \\
ANSM        & Agence Nationale de Sécurité du Médicament 
et des produits de santé (National drug and medical devices agency) \\
CPP         & Comité de Protection des Personnes (Ethics Committee) \\
CNIL        & Commission Nationale Informatique et Liberté (French data protection agency)  \\
CER         & Clinical Evaluation Report            \\
IFU         & Instructions For Use                  \\
NC          & Non-conformity                        \\
PMSR        & Post-Market Surveillance Report       \\
PSUR        & Periodic Safety Update Report         \\
CAPA        & Corrective and Preventive Actions     \\ 
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

答案2

表格的宽度几乎等于\textwidth。为什么不直接设置为 呢\textwidth?然后使用tabularx环境,允许第二列自动换行,并发出指令

\renewcommand\tabularxcolumn[1]{m{#1}}

X在非列中诱导垂直居中

在此处输入图片描述

\documentclass[12pt]{article}
    %\usepackage[utf8]{inputenc} % that's the default nowadays
    \usepackage[T1]{fontenc}
    %%\usepackage[french]{babel}
    %\usepackage{graphicx}
    \usepackage[hmargin=1.27cm,top=0.7cm,bottom=1.3cm]{geometry}
    %\usepackage{array,multirow,makecell}
    %%%\usepackage{colortbl} 
    \usepackage[table]{xcolor}
    %%%\usepackage{here}
    %\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
    %\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
    %\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
    
    \usepackage{tabularx}
    \renewcommand\tabularxcolumn[1]{m{#1}} % vertical centering
    
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    % pour les pieds de page:
    \cfoot{\scriptsize Trame du document : FOR\_TEMPLATE}
    \rfoot{\scriptsize\color{red} Ne pas reproduire \slash\ Copie contrôlée}
    
    \begin{document}
    
    \begin{table}[!h]
    \setlength\extrarowheight{2pt}
    \begin{tabularx}{\textwidth}{|l|X|}
            \hline
            \rowcolor[RGB]{33,88,104}\multicolumn{2}{|c|}{%
                \textbf{\color{white}Abbreviation}} \\ \hline
            \textbf{Abbreviation} &  \textbf{Meaning} \\ \hline
            COO  & Chief Operating Officer \\ \hline
            RQ \& AR & Regulatory Affairs and Quality Manager \\ \hline
            ANSM & Agence Nationale de Sécurité du Médicament et des produits de santé 
                   (National drug and medical devices agency) \\ \hline
            CPP  & Comité de Protection des Personnes (Ethics Committee) \\ \hline
            CNIL & Commission Nationale Informatique et Liberté 
                   (French data protection agency) \\ \hline
            CER  & Clinical Evaluation Report \\ \hline 
            IFU  & Instructions For Use \\ \hline
            NC   & Non-conformity \\ \hline
            PMSR & Post-Market Surveillance Report \\ \hline
            PSUR & Periodic Safety Update Report \\ \hline
            CAPA & Corrective and Preventive Actions \\ \hline
    \end{tabularx}
    \end{table}
    
    \end{document}

附录:虽然上述解决方案可能满足 OP 的直接要求,但我认为不能说该表格看起来有吸引力或有趣。如果您重视与读者的有效沟通,您可能希望通过 (a) 删除所有垂直线和大多数水平线以及 (b) 简化标题材料,使表格更具视觉吸引力,就像以下解决方案中追求的那样。我希望您会同意我的观点,即这个表格看起来比上面显示的表格更具吸引力。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[hmargin=1.27cm,top=0.7cm,bottom=1.3cm]{geometry}
\usepackage[table]{xcolor}

\usepackage{tabularx}
\newcolumntype{N}{>{\raggedright\arraybackslash}X}
\usepackage{booktabs} % for \addlinespace and \bottomrule macros
\newcommand\Tstrut{\rule{0pt}{2.6ex}} % 'top' (typographic) strut

\begin{document}

\begin{table}[!h] 
\begin{tabularx}{\textwidth}{@{} l N @{}} 
\rowcolor[RGB]{33,88,104}\multicolumn{2}{c}{%
\textbf{\color{white}Acronyms and their meanings\Tstrut}} \\ 
COO  & Chief Operating Officer\Tstrut \\ 
RQ \& AR & Regulatory Affairs and Quality Manager \\ 
ANSM & Agence Nationale de Sécurité du Médicament et des produits  
       de santé (National drug and medical devices agency) \\ 
\addlinespace
CPP  & Comité de Protection des Personnes (Ethics Committee) \\ 
CNIL & Commission Nationale Informatique et Liberté 
       (French data protection agency) \\ 
CER  & Clinical Evaluation Report \\  
IFU  & Instructions For Use \\ 
\addlinespace
NC   & Non-conformity \\ 
PMSR & Post-Market Surveillance Report \\ 
PSUR & Periodic Safety Update Report \\ 
CAPA & Corrective and Preventive Actions \\ 
\bottomrule
\end{tabularx}
\end{table}

\end{document}

答案3

如果您只想修改该单元格,您可以使用:

\multicolumn{1}{|>{\centering\arraybackslash }m{3cm}}{ANSM}

而不是单元格内容。

如果您希望所有单元格垂直居中,那么您可以使用:

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }m{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }m{#1}}

代替:

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}

在你的序言中。

相关内容