我试图让这个表格适合页面宽度,但做不到。我尝试了 tabularx 环境,但内容混在一起了。我也尝试了 tabulary 环境:效果更好,内容没有混在一起,但表格超出了页面宽度。
我使用 tabularx 为表格使用的代码如下:
`\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{caption}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{footmisc}
\begin{document}
\begin{table}
\scalebox{1}{
\begin{minipage}{1\textwidth}
\centering
\caption{aaaaa aaaaa aaaa aaaa}
\begin{tabularx}{1\textwidth} {X X X X X X X X}
\toprule
Aaaaa aaa & Bbbbbbbbb & \multicolumn{2}{l}{CCCCCC CCCcccccc} & \multicolumn{2}{l}{Dddddddd} & \multicolumn{2}{l}{Eeeeeeeeee\footnote{ccccc ccccc cc} eeeeeee eeeeeee} \\
\midrule
\multirow{5}[9]{*}{Kitchen} & Refrigerator & 40 & & \multicolumn{1}{l}{14} & \multicolumn{1}{l}{\multirow{5}[9]{*}{40}} & \multirow{2}[4]{*}{28} & \multirow{5}[9]{*}{55} \\
& Separate freezer & 40 & & \multicolumn{1}{l}{10} & \multicolumn{1}{l}{} & & \\
& Dishwasher & 40 & & \multicolumn{1}{l}{7} & \multicolumn{1}{l}{} & \multirow{2}[4]{*}{16} & \\
& Washing machine & 40 & & \multicolumn{1}{l}{9} & \multicolumn{1}{l}{} & & \\
& Others & 40 & & \multicolumn{1}{l}{-} & \multicolumn{1}{l}{} & 11 & \\
\multirow{2}[3]{*}{Electric equipment} & Informatics & \multicolumn{2}{l}{\multirow{2}[3]{*}{33}} & \multicolumn{1}{l}{7} & \multicolumn{1}{l}{\multirow{2}[3]{*}{13}} & 12 & \multirow{2}[3]{*}{21} \\
& Entertainment & \multicolumn{2}{l}{} & \multicolumn{1}{l}{6} & \multicolumn{1}{l}{} & 9 & \\
\multicolumn{2}{l}{Lighting systems} & \multicolumn{2}{l}{13} & \multicolumn{2}{l}{8} & \multicolumn{2}{l}{18} \\
\multirow{3}[6]{*}{HVAC} & Air heating & \multicolumn{1}{l}{9} & \multicolumn{1}{l}{\multirow{3}[6]{*}{11}} & 9 & & \multicolumn{2}{l}{\multirow{2}[4]{*}{n. a.}} \\
& Air cooling & \multicolumn{1}{l}{2} & \multicolumn{1}{l}{} & 9 & & \multicolumn{2}{l}{} \\
& Air conditioner & \multicolumn{1}{l}{-} & \multicolumn{1}{l}{} & 9 & & \multicolumn{2}{l}{2} \\
\multicolumn{2}{l}{Water heating} & \multicolumn{2}{l}{2} & \multicolumn{2}{l}{-} & \multicolumn{2}{l}{n. a.} \\
\multicolumn{2}{l}{Others} & \multicolumn{2}{l}{-} & \multicolumn{2}{l}{30} & \multicolumn{2}{l}{4} \\
\bottomrule
\end{tabularx}
\label{tab:comp_dist_cons_dif_sourc}
\end{minipage}}
\end{table}
\end{document}`
对于表格,我替换:\begin{tabularx}{1\textwidth} {XXXXXXXX} ... \end{tabularx}
通过这个:\begin{tabulary}{1\textwidth} {JJJJJJJJ} \end{tabulary}
我得到了这个:
有没有办法可以同时调整表格内容和表格宽度?提前谢谢您。
答案1
标题太宽,表格放不下。您需要强制减小标题的宽度,一种解决方案是将多列标题放在p
指定大小的类型列中:
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{footmisc}
\begin{document}
\begin{table}
\begin{minipage}{1.0\linewidth}
\centering
\caption{aaaaa aaaaa aaaa aaaa}
\begin{tabulary}{1\textwidth} {J J J J J J J J}
\toprule Aaaaa aaa & Bbbbbbbbb & \multicolumn{2}{p{2cm}}{CCCCCC
CCCcccccc} & \multicolumn{2}{p{2cm}}{Dddddddd} &
\multicolumn{2}{p{2cm}}{Eeeeeeeeee\footnote{ccccc ccccc cc}
eeeeeee eeeeeee} \\
\midrule \multirow{5}[9]{*}{Kitchen} & Refrigerator & 40 & &
\multicolumn{1}{l}{14} &
\multicolumn{1}{l}{\multirow{5}[9]{*}{40}} &
\multirow{2}[4]{*}{28} & \multirow{5}[9]{*}{55} \\
& Separate freezer & 40 & & \multicolumn{1}{l}{10} &
\multicolumn{1}{l}{} & & \\
& Dishwasher & 40 & & \multicolumn{1}{l}{7} &
\multicolumn{1}{l}{} & \multirow{2}[4]{*}{16} & \\
& Washing machine & 40 & & \multicolumn{1}{l}{9} &
\multicolumn{1}{l}{} & & \\
& Others & 40 & & \multicolumn{1}{l}{-} &
\multicolumn{1}{l}{} & 11 & \\
\multirow{2}[3]{*}{Electric equipment} & Informatics &
\multicolumn{2}{l}{\multirow{2}[3]{*}{33}} &
\multicolumn{1}{l}{7} &
\multicolumn{1}{l}{\multirow{2}[3]{*}{13}} & 12 &
\multirow{2}[3]{*}{21} \\
& Entertainment & \multicolumn{2}{l}{} & \multicolumn{1}{l}{6} &
\multicolumn{1}{l}{} & 9 & \\
\multicolumn{2}{l}{Lighting systems} & \multicolumn{2}{l}{13} &
\multicolumn{2}{l}{8} & \multicolumn{2}{l}{18} \\
\multirow{3}[6]{*}{HVAC} & Air heating & \multicolumn{1}{l}{9} &
\multicolumn{1}{l}{\multirow{3}[6]{*}{11}} & 9 & &
\multicolumn{2}{l}{\multirow{2}[4]{*}{n. a.}} \\
& Air cooling & \multicolumn{1}{l}{2} & \multicolumn{1}{l}{} & 9
& & \multicolumn{2}{l}{} \\
& Air conditioner & \multicolumn{1}{l}{-} & \multicolumn{1}{l}{}
&
9 & & \multicolumn{2}{l}{2} \\
\multicolumn{2}{l}{Water heating} & \multicolumn{2}{l}{2} &
\multicolumn{2}{l}{-} & \multicolumn{2}{l}{n. a.} \\
\multicolumn{2}{l}{Others} & \multicolumn{2}{l}{-} &
\multicolumn{2}{l}{30} & \multicolumn{2}{l}{4} \\
\bottomrule
\end{tabulary}
\label{tab:comp_dist_cons_dif_sourc}
\end{minipage}
\end{table}
\end{document}