我创建了一个表格,其中合并了一些行单元格。因此,合并后的单元格未“对齐”,因为两列的宽度不同。当您查看表格的插图时,这一点更加明显:
如您所见,星号未与第 2 列和第 3 列的中间对齐。我原本想为这两列设置固定的列宽,但老实说,我不知道该怎么做。为了方便起见,我一直在使用 tablegenerator.com。我已附上用于生成下表的代码:
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table}[h]
\centering
\small
\begin{tabular}{|lcc|}
\hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Alford (1992)}} & {\color[HTML]{FFFFFF} \textbf{SIC}} & {\color[HTML]{FFFFFF} \textbf{SIC\Plus ROE}} \\ \hline
P/E & 24.5\% & 23.9\% \\
Pairwise difference significance & \multicolumn{2}{c|}{\textbf{*}} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{0.6\%}} \\ \hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Cheng and McNamara (2000)}} & {\color[HTML]{FFFFFF} \textbf{SIC}} & {\color[HTML]{FFFFFF} \textbf{SIC\Plus ROE}} \\ \hline
P/E & 27.6\% & 26.4\% \\
Pairwise difference significance & \multicolumn{2}{c|}{\textbf{***}} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{1.2\%}} \\ \hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Dittmann and Weiner (2005)}} & {\color[HTML]{FFFFFF} \textbf{SIC}} & {\color[HTML]{FFFFFF} \textbf{ROA\Plus Size}} \\ \hline
EV/EBIT & 33.4\% & 30.6\% \\
Pairwise difference significance & \multicolumn{2}{c|}{\textbf{***}} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{2.8\%}} \\ \hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Plenborg et al. (2017)}} & {\color[HTML]{FFFFFF} \textbf{GICS}} & {\color[HTML]{FFFFFF} \textbf{SARD}} \\ \hline
EV/EBIT & 25.5\% & 20.3\% \\
Pairwise difference significance & \multicolumn{2}{c|}{\textbf{***}} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{5.2\%}} \\ \hline
\end{tabular}
\end{table}
\end{document}
答案1
在p{...}
第二列和第三列中定义了新的命令:
\documentclass[a4paper,11pt]{report}
\usepackage[table,xcdraw]{xcolor}
\usepackage{array}
\newcommand\mclw[1]{\multicolumn{1}{l}{\color{white}\textbf{#1}}}
\newcommand\mccw[1]{\multicolumn{1}{c}{\color{white}\textbf{#1}}}
\newcommand\mcpc[1]{\multicolumn{2}{>{\centering\arraybackslash}p{8em}|}{\textbf{#1}}}
\begin{document}
\begin{table}[ht]
\centering
\small
\begin{tabular}{|l >{\centering\arraybackslash}p{3em}<{\,\%}
>{\centering\arraybackslash}p{5em}<{\,\%}|}
\hline
\rowcolor[HTML]{003085}
\mclw{Alford (1992)} & \mccw{SIC} & \mccw{SIC{+}ROE} \\
\hline
P/E & 24.5 & 23.9\% \\
Pairwise difference significance & \mcpc{*} \\
Simple pairwise difference & \mcpc{0.6\,\%} \\
\hline
\rowcolor[HTML]{003085}
\mclw{Cheng and McNamara (2000)} & \mccw{SIC} & \mccw{SIC{+}ROE} \\
P/E & 27.6 & 26.4 \\
Pairwise difference significance & \mcpc{***} \\
Simple pairwise difference & \mcpc{1.2\,\%} \\
\hline
\rowcolor[HTML]{003085}
\mclw{Dittmann and Weiner (2005)} & \mccw{SIC} & \mccw{SIC{+}Size} \\
EV/EBIT & 33.4 & 30.6 \\
Pairwise difference significance & \mcpc{***} \\
Simple pairwise difference & \mcpc{2.8\,\%} \\
\hline
\rowcolor[HTML]{003085}
\mclw{Plenborg et al. (2017)} & \mccw{SIC} & \mccw{SARD} \\
EV/EBIT & 25.5 & 20.3 \\
Pairwise difference significance & \mcpc{***} \\
Simple pairwise difference & \mcpc{5.2\,\%} \\
\hline
\end{tabular}
\end{table}
\end{document}
答案2
尝试以下版本。我认为星号现在与第二列和第三列之间的假想线对齐,但我不确定这是您期望的最终布局:
\documentclass{article}
\usepackage{bbding} % (<- put here the package you use for \Plus symbol)
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table}[h]
\centering
\small
\begin{tabular}{|lcl|}
\hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Alford (1992)}} & {\color[HTML]{FFFFFF} \textbf{SIC}} & {\color[HTML]{FFFFFF} \textbf{SIC\Plus ROE}} \\ \hline
P/E & 24.5\% & 23.9\% \\
Pairwise difference significance & & \textbf{*} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{0.6\%}} \\ \hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Cheng and McNamara (2000)}} & {\color[HTML]{FFFFFF} \textbf{SIC}} & {\color[HTML]{FFFFFF} \textbf{SIC\Plus ROE}} \\ \hline
P/E & 27.6\% & 26.4\% \\
Pairwise difference significance & & \textbf{***} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{1.2\%}} \\ \hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Dittmann and Weiner (2005)}} & {\color[HTML]{FFFFFF} \textbf{SIC}} & {\color[HTML]{FFFFFF} \textbf{ROA\Plus Size}} \\ \hline
EV/EBIT & 33.4\% & 30.6\% \\
Pairwise difference significance & & \textbf{***} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{2.8\%}} \\ \hline
\rowcolor[HTML]{003085}
{\color[HTML]{FFFFFF} \textbf{Plenborg et al. (2017)}} & {\color[HTML]{FFFFFF} \textbf{GICS}} & {\color[HTML]{FFFFFF} \textbf{SARD}} \\ \hline
EV/EBIT & 25.5\% & 20.3\% \\
Pairwise difference significance & & \textbf{ ***} \\
Simple pairwise difference & \multicolumn{2}{c|}{\textbf{5.2\%}} \\ \hline
\end{tabular}
\end{table}
\end{document}
答案3
包裹卡路里也非常适合构建这样的表格:
\documentclass[a4paper, 12pt]{report}
\usepackage{mathpazo, cals}
\usepackage[table, x11names]{xcolor}
\definecolor{darkblue}{HTML}{003085}
\let\nc=\nullcell % Shortcuts
\let\sc=\spancontent
\begin{document}
\begin{calstable}[c]
% Defining column relativ to each other and relativ to the margins
\colwidths{{\dimexpr(\columnwidth)/20*12\relax}
{\dimexpr(\columnwidth)/20*4\relax}
{\dimexpr(\columnwidth)/20*4\relax}
}
% The tabular fills the text area if sum of all columns is 20
% Set up the tabular
\makeatletter
\def\cals@framers@width{0.4pt} % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.4pt}
\def\cals@bodyrs@width{0pt}
\cals@setpadding{Ag}
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0pt} % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0pt}
\def\cals@bgcolor{}
\def\blue{\ifx\cals@bgcolor\empty
\def\cals@bgcolor{darkblue}
\else \def\cals@bgcolor{} \fi}
% R1H1
\brow
\bfseries\blue\cell{\textcolor{white}{Alford (1992)}}
\alignC\cell{\textcolor{white}{SIC}}
\alignC\cell{\textcolor{white}{SIC+ROE}}\blue\mdseries
\erow
%R2H2
\brow
\alignL\cell{P/E}
\alignC\cell{24.5\,\%}
\alignC\cell{23.9\,\%}
\erow
%R3B1
\brow
\alignL\cell{Pairwise difference significance}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries *}
\erow
% R4B2
\brow
\alignL\cell{Simpel pairwise difference}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries 0.6\,\%}
\erow
%R5B3
% R1H1
\brow
\bfseries\blue\alignL\cell{\vfil\textcolor{white}{Cheng and McNamara (2000)}}
\alignC\cell{\textcolor{white}{SIC}}
\alignC\cell{\textcolor{white}{SIC+ROE}}\blue\mdseries
\erow
%R2H2
\brow
\alignL\cell{P/E}
\alignC\cell{27.6\,\%}
\alignC\cell{26.4\,\%}
\erow
%R3B1
\brow
\alignL\cell{Pairwise difference significance}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries ***}
\erow
% R4B2
\brow
\alignL\cell{Simpel pairwise difference}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries 1.2 \%}
\erow
% R1H1
\brow
\bfseries\blue\alignL\cell{\vfil\textcolor{white}{Dittmann and Weiner (2005)}}
\alignC\cell{\textcolor{white}{SIC}}
\alignC\cell{\textcolor{white}{SIC+Size}}\blue\mdseries
\erow
%R2H2
\brow
\alignL\cell{EV/EBIT}
\alignC\cell{33.4\,\%}
\alignC\cell{30.6\,\%}
\erow
%R3B1
\brow
\alignL\cell{Pairwise difference significance}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries ***}
\erow
% R4B2
\brow
\alignL\cell{Simpel pairwise difference}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries 2.8 \%}
\erow
% R1H1
\brow
\bfseries \blue\alignL\cell{\textcolor{white}{Plenborg et al. (2017)}}
\alignC\cell{\textcolor{white}{SIC}}
\alignC\cell{\textcolor{white}{SIC+ROE}}\blue\mdseries
\erow
%R2H2
\brow
\alignL\cell{P/E}
\alignC\cell{25.5\,\%}
\alignC\cell{20.3\,\%}
\erow
%R3B1
\brow
\alignL\cell{Pairwise difference significance}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries ***}
\erow
% R4B2
\brow
\alignL\cell{Simpel pairwise difference}
\nc{ltb}
\nc{rtb}\alignC\sc{\bfseries 5.2\,\%}
\erow
\makeatletter
\end{calstable}\par
\end{document}