我创建了下表:
使用以下代码:
\documentclass{standalone}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{color}
\usepackage{xcolor, colortbl}
\begin{document}
\def\arraystretch{1.5}
\begin{tabular}{L{5.75cm}|R{1.25cm}|R{1.25cm}|R{1.25cm}|R{1.25cm}|R{1.25cm}|R{1.25cm}|R{1.25cm}}
\multicolumn{8}{l}{\textbf{Table 2: GDP by Economic Activity (at constant 2015 prices)}} \\
\hline\hline
& \multirowcell{3}{2019 \\ share \\ \%} & \multicolumn{6}{c}{Annual growth, \%} \\
\hhline{~~------}
& & \multicolumn{2}{c|}{2018} & \multicolumn{4}{c}{\cellcolor{blue!10!white} 2019} \\
\hhline{~~------}
& & 3Q & 4Q & 1Q & 2Q & 3Q & {\cellcolor{blue!10!white} 4Q} \\
\hline
Services & 57.7 & 7.3 &6.9 & & & & \cellcolor{blue!10!white} \\
Manufacturing & 22.3 & 5.0 & 4.7 & & & & \cellcolor{blue!10!white} \\
Mining & 7.1 & $-$5.7 & $-$0.7 & & & & \cellcolor{blue!10!white} \\
Agriculture & 7.1 & $-$0.8 & $-$0.1 & & & & \cellcolor{blue!10!white} \\
Construction & 4.7 & 4.7 & 2.6& & & & \cellcolor{blue!10!white} \\ \hline
Real GDP$^1$ & 100.0 & 4.4 & 4.7 & & & & \cellcolor{blue!10!white} \\ \hline
\multicolumn{8}{l}{\small $^1$Shares do not add up due to rounding and exclusion of import duties.} \\
\multicolumn{8}{l}{\small Source: Department of Statistics Malaysia} \\ \hline
\end{tabular}
\end{document}
我想要改变的是将最后 6 列(带有子标题 3Q、4Q 等的列)向左“移动”,但不删除右对齐。
这样做的原因是,从印刷上来说,数字应该右对齐,以便于阅读。但是,为了美观,我希望整个右对齐的数字块都居中。
类似这样的情况是:
\begin{center}
\begin{minipage}
\flushright
Text
\end{minipage}
\end{center}
这样,小页面本身就居中,但其中的文本却不居中。
我怎样才能实现这个目标?
答案1
列S
类型(来自siunitx
)已为您完成!我添加了一些简化:当您加载时xcolor
,您不必加载color
。同样,使用选项加载它[table]
。colortbl
我擅自将注释分组到表格底部的同一行,但如果您愿意,您可以轻松恢复到原始布局。
请注意,在S
列中,如果在内容周围添加一对括号,非数字单元格的内容将位于中心。
\documentclass[border = 6pt]{standalone}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\begin{document}
\sisetup{table-format=-1.1, table-number-alignment=center, table-column-width=1.25cm}
\def\arraystretch{1.5}
\begin{tabular}{L{5.75cm}|S[table-format=3.1]|*{5}{S|}S}
\multicolumn{8}{l}{\textbf{Table 2: GDP by Economic Activity (at constant 2015 prices)}} \\
\hline\hline
& {\multirowcell{3}{2019 \\ share \\ \%}} & \multicolumn{6}{c}{Annual growth, \%} \\
\hhline{~~------}
& & \multicolumn{2}{c|}{2018} & \multicolumn{4}{c}{\cellcolor{blue!10!white} 2019} \\
\hhline{~~------}
& & {3Q} & {4Q} & {1Q} & {2Q} & {3Q} & {\cellcolor{blue!10!white} 4Q} \\
\hline
Services & 57.7 & 7.3 &6.9 & & & & \cellcolor{blue!10!white} \\
Manufacturing & 22.3 & 5.0 & 4.7 & & & & \cellcolor{blue!10!white} \\
Mining & 7.1 & -5.7 & -0.7 & & & & \cellcolor{blue!10!white} \\
Agriculture & 7.1 & -0.8 & -0.1 & & & & \cellcolor{blue!10!white} \\
Construction & 4.7 & 4.7 & 2.6& & & & \cellcolor{blue!10!white} \\ \hline
Real GDP$^1$ & 100.0 & 4.4 & 4.7 & & & & \cellcolor{blue!10!white} \\ \hline
\multicolumn{4}{@{}l}{\small $^1$Shares do not add up due to rounding and exclusion of import duties.}
& \multicolumn{4}{r@{}}{\small Source: Department of Statistics Malaysia} \\ \hline
\end{tabular}
\end{document}