尽管在标题中明确定义了,但表格定义的列没有居中对齐

尽管在标题中明确定义了,但表格定义的列没有居中对齐

我有一份类似的文件:

\documentclass[12pt]{report}
 \usepackage{array,ltablex,makecell}% ltablex loads tabularx and longtable also
\renewcommand\theadfont{\normalsize\bfseries}
 \newenvironment{conditions}
 {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
 {\end{tabular}\par\vspace{\belowdisplayskip}}%This is for descriptions of equations
\usepackage[]{multirow}%Essential for cells in table spanning multiple rows
% \usepackage{tabulary}% This is for tables
\usepackage{ragged2e}% This is formatting for long tables
\usepackage[font={small}]{caption}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{U}{>{\raggedright\arraybackslash\hspace{0pt}}X}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}%C is for central aligned columns and middle aligned, p puts stuff at the bottom, m middles everything.
\newcolumntype{Y}{>{\centering\arraybackslash\hspace{0pt}}X}%C is for central aligned columns and middle aligned.
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{booktabs,dcolumn,caption}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}%This is for precision tables per property
%

\begin{document}

\begin{table}[!ht]
\scriptsize
\catcode`_=13 % Make _ "active"; 
%% This setting expires at end of current group, i.e., at end of "table" environment
\def_{\textunderscore\hspace{0pt}} % "meaning" of "_"
    \centering
    \setlength\tabcolsep{0pt}
    \begin{tabular}{ C{2.5cm}C{6.5cm}C{3cm}C{3cm}}
    \toprule
      \multicolumn{4}{L{14.5cm}}{``Countries with higher GDP per capita \ldots include \texttt{LOCATION\_SLOT} (around \$\texttt{NUMBER\_SLOT}), and \ldots we find Luxembourg (\$ 122,147).''}  \\ \cmidrule{1-4}

      \multirow{2}{2.5cm}{\textbf{Extracted Region-Value}} & \multirow{2}{6.5cm}{\textbf{KB Properties for Region} } & \multicolumn{2}{C{6cm}}{\textbf{Assigned Label}} \\
      \cmidrule(lr){3-3}
\cmidrule(lr){4-4}
      & & 5\% APE Threshold  & Regular \\\midrule
      Azerbaijan : 7,500 & Azerbaijan: \{population:9,168,000, gdp_nominal_per_capita :1,193, size_of_armed_forces: 81,950, renewable_freshwater_per_capita: 2577 \ldots \} & \textit{no\_region} &  \textit{renewable_freshwater_per_capita}, APE = 0.65\\ \cmidrule{1-4}
      \multicolumn{4}{L{14.5cm}}{
      \textbf{Naive Cost Vector}:\{population:$\infty$, gdp_nominal_per_capita :$\infty$, size_of_armed_forces: $\infty$, renewable_freshwater_per_capita: 0 \ldots \}, \newline    
      \textbf{Cost Vector}:\{population:1221.4, gdp_nominal_per_capita :0.84, size_of_armed_forces: 9.92, renewable_freshwater_per_capita: 0.65 \ldots \}
}  \\ \bottomrule
    \end{tabular}
    \caption{Example Distant Supervision}
    \label{tbl:exampledistantsupervision}
    \normalsize
  \end{table}

\end{document}

结果是:

在此处输入图片描述

为什么我的列KB Properties per Region显示出来raggedright而不是居中?我的tabular列指定了C我在序言中定义的列类型为居中,这就是我不明白这一点的原因。

答案1

\multirow实际上是一个 parbox,因此暗示了两端对齐的文本,除非您指定其他内容,这里我只\centering在一个单元格的开头添加:

& \multirow{2}{6.5cm}{\centering\textbf{KB Properties for Region} } & 

生产

在此处输入图片描述

答案2

您可以使用\multirowcellmakecell我添加了一个小的垂直调整来考虑booktabs规则的垂直填充:

\documentclass[12pt]{report}
 \usepackage{array,ltablex,makecell}% ltablex loads tabularx and longtable also
\renewcommand\theadfont{\normalsize\bfseries}
 \newenvironment{conditions}
 {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
 {\end{tabular}\par\vspace{\belowdisplayskip}}%This is for descriptions of equations
\usepackage[]{multirow}%Essential for cells in table spanning multiple rows
% \usepackage{tabulary}% This is for tables
\usepackage{ragged2e}% This is formatting for long tables
\usepackage[font={small}]{caption}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{U}{>{\raggedright\arraybackslash\hspace{0pt}}X}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}%C is for central aligned columns and middle aligned, p puts stuff at the bottom, m middles everything.
\newcolumntype{Y}{>{\centering\arraybackslash\hspace{0pt}}X}%C is for central aligned columns and middle aligned.
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{booktabs,dcolumn,caption}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}%This is for precision tables per property
%

\begin{document}

\begin{table}[!ht]
\scriptsize
\catcode`_=13 % Make _ "active";
%% This setting expires at end of current group, i.e., at end of "table" environment
\def_{\textunderscore\hspace{0pt}} % "meaning" of "_"
    \centering
    \setlength\tabcolsep{0pt}
    \begin{tabular}{ C{2.5cm}C{6.5cm}C{3cm}C{3cm}}
    \toprule
      \multicolumn{4}{L{14.5cm}}{``Countries with higher GDP per capita \ldots include \texttt{LOCATION\_SLOT} (around \$\texttt{NUMBER\_SLOT}), and \ldots we find Luxembourg (\$ 122,147).''} \\ \cmidrule{1-4}
      \multirow{2}{\linewidth}[-\dimexpr\aboverulesep+\cmidrulewidth\relax]{\textbf{Extracted Region-Value}} & \multirowcell{2}[-\dimexpr\aboverulesep+\cmidrulewidth\relax]{\textbf{KB Properties for Region} } & \multicolumn{2}{C{6cm}}{\textbf{Assigned Label}} \\
      \cmidrule(lr){3-3}
\cmidrule(lr){4-4}
      & & 5\% APE Threshold & Regular \\\midrule
      Azerbaijan : 7,500 & Azerbaijan: \{population:9,168,000, gdp_nominal_per_capita :1,193, size_of_armed_forces: 81,950, renewable_freshwater_per_capita: 2577 \ldots \} & \textit{no\_region} & \textit{renewable_freshwater_per_capita}, APE = 0.65\\ \cmidrule{1-4}
      \multicolumn{4}{L{14.5cm}}{
      \textbf{Naive Cost Vector}:\{population:$∞$, gdp_nominal_per_capita :$∞$, size_of_armed_forces: $∞$, renewable_freshwater_per_capita: 0 \ldots \}, \newline
      \textbf{Cost Vector}:\{population:1221.4, gdp_nominal_per_capita :0.84, size_of_armed_forces: 9.92, renewable_freshwater_per_capita: 0.65 \ldots \}
} \\ \bottomrule
    \end{tabular}
    \caption{Example Distant Supervision}
    \label{tbl:exampledistantsupervision}
    \normalsize
  \end{table}

\end{document} 

在此处输入图片描述

相关内容