5

I need my table to fit into the page width even if it has to be shrinked a bit. I looked at similar questions which suggest using resizebox. I used it but the table content exceeds the page width.

\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}

The output: enter image description here

4
  • As far as I see, you created an example where it is impossible to fit the content. So you want to force it, even if it overlaps, do you? Commented Feb 17, 2017 at 14:47
  • @MaestroGlanz Thanks. I want to force it by making the font smaller. No overlap. Commented Feb 17, 2017 at 14:55
  • I dont think, it is possible to automatically adapt the font size, so that it fits. You can write a macro, which helps you doing this manually. Commented Feb 17, 2017 at 15:11
  • It should be possible to write a macro, which shrinks the size for every compilation, until it fits. Commented Feb 17, 2017 at 15:13

2 Answers 2

6

I suggest you swap rows and columns. Your table then can fit a single column. Here is an example of what you can get:

\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} 

enter image description here

3

As your table's natural width is wider than the page you should just use an ordinary tabular and move the \centering outside the \resizebox. Here is the output with the vertical lines showing the text boundaries via the showframe package:

Sample output

\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}

I have simplified your table a bit, you had several empty columns that seemed superfluous.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .