我在有多行的列中缺少右边框。尝试了很多方法。这是一个例子。
\documentclass[10pt]{article}
\usepackage{array}
\usepackage{multicol,graphicx}
\usepackage{multirow}
\usepackage{lscape}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}
\setlength{\columnsep}{5pt}
\begin{document}
\begin{landscape}
\begin{table}[htbp]
\begin{tabular}{>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1cm}>{\raggedright}p{1.6cm}>{\raggedright}p{1.5cm}} \hline
\multicolumn{1}{c|}{} & \multicolumn{10}{|c|}{\textbf{End-Use Sectors}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1.6cm}|}{\multirow{2}{=}{\textbf{E. Power Sector}}} & \multicolumn{1}{|c}{} \tabularnewline \cline{2-11}
\multicolumn{1}{c|}{} & \multicolumn{5}{|>{\centering}p{5cm}|}{\textbf{Transportation}} & \multicolumn{5}{|>{\centering}p{5cm}|}{\textbf{Total}} & & \tabularnewline \cline{2-12}
& \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Primary}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Electricity}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{End-Use}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Energy Losses}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Total Energy}} &
\multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Primary}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Electricity}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{End-Use}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Energy Losses}} &
\multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1cm}|}{\textbf{Total Energy}} &
\multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1.6cm}|}{\textbf{Primary}} & \multicolumn{1}{|>{\raggedright\hspace{0pt}}p{1.5cm}}{\textbf{Primary Total}} \tabularnewline \hline
1949 & 7880 & 22 & 7902 & 88 & 7990 & 27628 & 868 & 28497 & 3471 & 31968 & 4339 & 31968 \tabularnewline
1950 & 8383 & 23 & 8407 & 86 & 8492 & 29919 & 994 & 30914 & 3685 & 34599 & 4679 & 34599 \tabularnewline
1951 & 8933 & 24 & 8958 & 84 & 9042 & 31883 & 1127 & 33010 & 3944 & 36953 & 5071 & 36954 \tabularnewline
\end{tabular}%
\end{table}
\end{landscape}
\end{document}
答案1
清理代码中的混乱后,我得到了以下结果:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multicol,graphicx}
\usepackage{array}
\usepackage{multirow}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash\hspace{0pt}}p{#1}}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{table}[htbp]
\centering
\setlength\tabcolsep{4pt}
\setlength\extrarowheight{2pt}
\small
\begin{tabular}{|l | *{12}{P{1.5cm}|} }
\hline
& \multicolumn{10}{c|}{\textbf{End-Use Sectors}}
& \multirow{2}{=}{\textbf{E. Power Sector}}
& \\
\cline{2-11}
& \multicolumn{5}{c|}{\textbf{Transportation}}
& \multicolumn{5}{c|}{\textbf{Total}}
& & \\
\cline{2-12}
& \textbf{Primary}
& \textbf{Electricity}
& \textbf{End-Use}
& \textbf{Energy Losses}
& \textbf{Total Energy}
& \textbf{Primary}
& \textbf{Electricity}
& \textbf{End-Use}
& \textbf{Energy Losses}
& \textbf{Total Energy}
& \textbf{Primary}
& \textbf{Primary Total} \\
\hline
1949 & 7880 & 22 & 7902 & 88 & 7990 & 27628
& 868 & 28497 & 3471 & 31968 & 4339 & 31968 \\
1950 & 8383 & 23 & 8407 & 86 & 8492 & 29919
& 994 & 30914 & 3685 & 34599 & 4679 & 34599 \\
1951 & 8933 & 24 & 8958 & 84 & 9042 & 31883
& 1127 & 33010 & 3944 & 36953 & 5071 & 36954 \\
\end{tabular}%
\end{table}
\end{landscape}
\end{document}
附录:
但是,如果您愿意使用该tabularray
包,代码会变得非常短:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tabularray}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{table}[htbp]
\centering
\setlength\tabcolsep{4pt}
\small
\begin{tblr}{hlines, vlines,
colspec = {l *{12}{X[c]} },
colsep=4pt,
row{1-3} = {font=\bfseries, m}
}
& \SetCell[c=10]{c} End-Use Sectors
& & & & & & & & & & \SetCell[r=2]{c} E. Power Sector
& \SetCell[r=2]{c} \\
& \SetCell[c=5]{c} Transportation
& & & & & \SetCell[c=5]{c} Total
& & & & & & \\
& Primary
& Electri\-city
& End-Use
& Energy Losses
& Total Energy
& Primary
& Electri\-city
& End-Use
& Energy Losses
& Total Energy
& Primary
& Primary Total \\
1949 & 7880 & 22 & 7902 & 88 & 7990 & 27628
& 868 & 28497 & 3471 & 31968 & 4339 & 31968 \\
1950 & 8383 & 23 & 8407 & 86 & 8492 & 29919
& 994 & 30914 & 3685 & 34599 & 4679 & 34599 \\
1951 & 8933 & 24 & 8958 & 84 & 9042 & 31883
& 1127 & 33010 & 3944 & 36953 & 5071 & 36954 \\
\end{tblr}%
\end{table}
\end{landscape}
\end{document}
编译结果为:
答案2
我会比@Zarko 走得更远他的回答并且 (a) 删除所有垂直线,并用booktabs
包中间距合适的水平线替换间距不当的水平线,并且 (b) 删除大胆的在表格的标题行中。
\documentclass[10pt]{article}
\usepackage[english]{babel}
\usepackage{multirow,pdflscape}
\usepackage[margin=1in]{geometry}
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{array} % for \newcolumntype macro
\newcolumntype{Q}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}
\begin{document}
\begin{landscape}
\begin{table}[htbp]
\centering
\begin{tabular}{@{} *{11}{c} Q{1.4cm} c @{}}
\toprule
&
\multicolumn{10}{c}{End-Use Sectors} &
\multicolumn{1}{Q{1.4cm}}{\multirow{2.4}{=}{E.\ Power Sector}} \\
\cmidrule(lr){2-11}
&
\multicolumn{5}{c}{Transportation} &
\multicolumn{5}{c}{Total} & \\
\cmidrule(lr){2-6} \cmidrule(lr){7-11} \cmidrule(lr){12-12}
&
\multicolumn{1}{Q{1.2cm}}{Primary} &
\multicolumn{1}{Q{1.2cm}}{Electricity} &
\multicolumn{1}{Q{1.2cm}}{End-Use} &
\multicolumn{1}{Q{1.2cm}}{Energy Losses} &
\multicolumn{1}{Q{1.2cm}}{Total Energy} &
\multicolumn{1}{Q{1.2cm}}{Primary} &
\multicolumn{1}{Q{1.2cm}}{Electricity} &
\multicolumn{1}{Q{1.2cm}}{End-Use} &
\multicolumn{1}{Q{1.2cm}}{Energy Losses} &
\multicolumn{1}{Q{1.2cm}}{Total Energy} &
\multicolumn{1}{Q{1.4cm}}{Primary} &
\multicolumn{1}{Q{1.3cm}@{}}{Primary Total} \\
\midrule
1949 & 7880 & 22 & 7902 & 88 & 7990 & 27628 & \phantom{0}868 & 28497 & 3471 & 31968 & 4339 & 31968 \\
1950 & 8383 & 23 & 8407 & 86 & 8492 & 29919 & \phantom{0}994 & 30914 & 3685 & 34599 & 4679 & 34599 \\
1951 & 8933 & 24 & 8958 & 84 & 9042 & 31883 & 1127 & 33010 & 3944 & 36953 & 5071 & 36954 \\
\bottomrule
\end{tabular}
\end{table}
\end{landscape}
\end{document}