如何缩小表格以适应页面宽度

如何缩小表格以适应页面宽度

我需要我的表格适合页面宽度,即使它必须缩小一点。我查看了类似的问题,建议使用resizebox。我用了它,但表格内容超出了页面宽度。

\documentclass[conference,compsoc]{IEEEtran}

%-------------------------for the table-----------------------------        
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}

\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}

\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
%for the images
\usepackage{graphicx} 
\graphicspath{ {images/} }
\usepackage{bmpsize}
%end images
%-------------------------end table-----------------------------
\begin{document}
\begin{table*} [t!]

\resizebox{\textwidth}{!}{%columnwidth
\centering
\begin{tabular*} {\textwidth} {ccccccccccccccccc}

  \toprule[1pt]
  & 
    \multicolumn{3}{c}{\head{Aaaaaaa}} &
    \multicolumn{1}{c}{\head{}} &
    \multicolumn{4}{c}{\head{BBBBBBB}}&
    \multicolumn{1}{c}{\head{}} &
    \multicolumn{2}{c}{\head{CCCCCCC}}&
    \multicolumn{1}{c}{\head{}} &
    \multicolumn{2}{c}{\head{DDDDDDD}}
\\

    \cmidrule(lr){2-4}
    \cmidrule(lr){6-9}
    \cmidrule(lr){11-12}
    \cmidrule(lr){14-15}

  & 
  \normal{\head{A.1111111111}} &
  \normal{\head{A.22222222222}} &
   \normal{\head{A.3333333333}} &
    \normal{\head{}} 

   &\normal{\head{B.111111111}} &
   \normal{\head{B.2222222222}} &
   \normal{\head{B.3333333333}} &
   \normal{\head{B.4444444444}} &
   \normal{\head{}} 

   & \normal{\head{C.1}} &
  \normal{\head{C.2}} &

  & \normal{\head{D.1}} &
  \normal{\head{D.2}} &

    \\

    \cmidrule(lr){1-11}

    \multirow{1}{*}{Test1}                &        & \cmark & & & &\cmark   &  & & \cmark & \\
    \cmidrule(lr){1-11}
    \multirow{1}{*}{Test2}               &        & \cmark & & &\cmark     &  & &        & \cmark  & \\
    \cmidrule(lr){1-11}
    \multirow{1}{*}{Test3}               & \cmark &        & & &  &\cmark  &  & & \cmark & \\
    \cmidrule(lr){1-11}
    \multirow{1}{*}{Test4} & \cmark &        & & &  &\cmark  &  & \cmark&  & \\

  \bottomrule[1pt]


\end{tabular*}
}%end resizebox
\end{table*}
\end{document}

输出: 在此处输入图片描述

答案1

我建议你交换行和列。这样你的表格就可以容纳一列。以下是你可以得到的结果示例:

\documentclass[conference,compsoc]{IEEEtran}

%-------------------------for the table-----------------------------
\usepackage{array}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{multirow}

\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}

\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
%for the images
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage{bmpsize}
%end images
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{table} [ht!]
  \centering\setlength\extrarowheight{3pt}
  \begin{tabular}{>{\bfseries}l>{\bfseries}l*{4}{c}}
    \toprule[1pt]
                                  & & Test1 & Test2 & Test3 & Test4 \\
    \midrule
                                  & A.1111111111 & & & \cmark & \cmark \\
    Aaaaaaa & A.22222222222 & \cmark & \cmark & & \\
    & A.3333333333 \\
    \arrayrulecolor{lightgray!20} \midrule[6pt]
                                  & B.1111111111 & & \cmark & & \\
    \multirow{3}{*}[1ex]{BBBBBBB} & B.2222222222 & \cmark & & \cmark & \cmark \\
    & B.3333333333 \\
    & B.4444444444 & & & \cmark \\
    \midrule[6pt]
    \multirow{2}{*}[-0.5ex]{CCCCCCC} & C.1 \\
    & C.2\\
    \midrule[6pt]
    \multirow{2}{*}[-0.5ex]{DDDDDDD} & D.1 \\
    & D.2\\
    \arrayrulecolor{black} \bottomrule[1pt]
  \end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

答案2

由于表格的自然宽度比页面宽,因此您应该使用普通的tabular并将 移到\centering之外\resizebox。以下是通过包显示文本边界的垂直线输出showframe

示例输出

\documentclass[conference,compsoc]{IEEEtran}

%-------------------------for the table-----------------------------
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}

\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}

\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
%for the images
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage{bmpsize}
%end images
%-------------------------end table-----------------------------
\usepackage{showframe} % to show page boundaries
\begin{document}

\begin{table*}[t!]
\centering
\resizebox{\textwidth}{!}{%columnwidth
\begin{tabular}{*{12}{c}}
  \toprule[1pt]
  & \multicolumn{3}{c}{\head{Aaaaaaa}}
  & \multicolumn{4}{c}{\head{BBBBBBB}}
  & \multicolumn{2}{c}{\head{CCCCCCC}}
  & \multicolumn{2}{c}{\head{DDDDDDD}} \\
  \cmidrule(lr){2-4}
  \cmidrule(lr){5-8}
  \cmidrule(lr){9-10}
  \cmidrule(lr){11-12}
  & \normal{\head{A.1111111111}}
  & \normal{\head{A.22222222222}}
  & \normal{\head{A.3333333333}}
  & \normal{\head{B.111111111}}
  & \normal{\head{B.2222222222}}
  & \normal{\head{B.3333333333}}
  & \normal{\head{B.4444444444}}
  & \normal{\head{C.1}}
  & \normal{\head{C.2}}
  & \normal{\head{D.1}}
  & \normal{\head{D.2}} \\
  \cmidrule(lr){1-12}
  \multirow{1}{*}{Test1} & & \cmark & \cmark & & & \cmark & & & \cmark
  & & \\
  \bottomrule[1pt]
\end{tabular}
}%end resizebox
\end{table*}
\end{document}

我稍微简化了您的表格,有几个空列看起来很冗余。

相关内容