1

I have the following code. My objective is to center all elements within the table and make the table fit within the page. I have searched for similar posts and found several, but none of their solutions could work for me.

\documentclass{IEEEtran}
\usepackage{cite}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\newtheorem{lem}{Lemma}
\newtheorem{cor}{Corollary}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\DeclareSymbolFont{matha}{OML}{txmi}{m}{it}% txfonts
\DeclareMathSymbol{\varv}{\mathord}{matha}{118}
\usepackage{caption}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{color}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{table*}[htbp]
    \centering
    \caption{Caption}
\begin{tabular}{|c|p{6.21em}|p{4.055em}|c|p{5.63em}|p{4.13em}|c|p{5.79em}|p{4.13em}|c|}
    \toprule
    & \multicolumn{3}{c|}{d=0.0005} & \multicolumn{3}{c|}{d=0.001} & \multicolumn{3}{c|}{d=0.002} \\
    \midrule
    \multicolumn{1}{|p{6.29em}|}{SNR} & Estimated \newline{}Direction & \multicolumn{1}{c|}{Adjusted \newline{} Angular Distance} & \multicolumn{1}{p{5em}|}{Mean Adj.\newline{}Angular \newline{}Deviation} & Estimated \newline{}Direction & \multicolumn{1}{c|}{Adjusted Angular Distance} & \multicolumn{1}{p{4.79em}|}{Mean Adj.\newline{}Angular \newline{}Deviation} & Estimated \newline{}Direction & \multicolumn{1}{c|}{Adjusted \newline{}Angular Distance} & \multicolumn{1}{p{5.21em}|}{Mean Adj.\newline{}Angular\newline{}Deviation} \\
    \midrule
    30    & (48.6, 46.8)\newline{}(138.6, 45.0) & 3.83\newline{}3.6 & 3.715 & (48.6, 45)\newline{}(138.6, 45) & 3.6\newline{}3.6 & 3.6   & (48.6, 46.8)\newline{}(135, 43.2) & 3.83\newline{}1.27 & 2.55 \\
    \midrule
    20    & (48.5, 45)\newline{}(140.4, 46.8) & 3.5\newline{}5.53 & 4.515 & (48.6, 41.4)\newline{}(140.4, 48.6) & 4.45\newline{}5.92 & 5.185 & (48.6, 41.4)\newline{}(142.2, 46.8) & 4.45\newline{}7.30 & 5.875 \\
    \midrule
    10    & \textbf{(46.8, 46.8)\newline{}(142.2, 41.4)} & 2.22\newline{}7.58 & 4.9   & (46.8, 46.8)\newline{}(142.2, 43.2) & 2.22\newline{}7.30 & 4.76  & \textbf{(48.6, 48.6)\newline{}(140.4, 43.2)} & 4.45\newline{}5.53 & 4.99 \\
    \bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%

enter image description here

Thank you for your help!

2
  • Welcome to TeX.SE](meta.tex.stackexchange.com/q/1436/4301). Please complete your code snippet to a MWE so someone can copy this and get started on solving the problem rather than completing your code. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. Obvious thing I can see is that you could put the title Adjusted Angular Distance over 3 lines and that will shrink those columns a lot. Should also eliminate the vertical rules. Jul 6, 2018 at 4:47
  • @PeterGrill That would may sense. In future posts, I will use MWE. Thank you!
    – Matthew
    Jul 6, 2018 at 19:14

1 Answer 1

5

The following example shows two different possible suggestions.

enter image description here

I have used the siunitx package in order to align the numbers with respect to the decimal separator. In order to make the table narrower so that in fits into the textwidth, I have either split the column headings into multiple lines or introduced abbreviations that are described underneath the table. I have also removed all vertical lines and included a variant with less horizontal lines but some additional white space.

\documentclass{IEEEtran}

\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{makecell}

\usepackage{etoolbox}% <-- for bold fonts
\newcommand{\ubold}{\fontseries{b}\selectfont}% <-- for bold fonts
\robustify\ubold% <-- for bold fonts

\begin{document}
\begin{table*}[htbp]
    \centering
    \caption{Caption}
\begin{tabular}{c
               *3{
                 r@{}
                 S[table-format=3.1]@{,~}
                 S[table-format=2.1]
                 @{}l
                 S[table-format=1.2]
                 S[table-format=1.3]
                  }
                }
    \toprule
    & \multicolumn{6}{c}{d=0.0005} & \multicolumn{6}{c}{d=0.001} & \multicolumn{6}{c}{d=0.002} \\
    \cmidrule(r){2-7} \cmidrule(lr){8-13} \cmidrule(l){14-19}
    {SNR} & \multicolumn{4}{c}{\makecell[cc]{Estimated\\ Direction}} & {\makecell[cc]{Adjusted\\ Angular\\ Distance}} & {\makecell[cc]{Mean Adjusted\\ Angular\\ Distance}} & \multicolumn{4}{c}{\makecell[cc]{Estimated\\ Direction}} & {\makecell[cc]{Adjusted\\ Angular\\ Distance}} & {\makecell[cc]{Mean Adjusted\\ Angular\\ Distance}} & \multicolumn{4}{c}{\makecell[cc]{Estimated\\ Direction}} & {\makecell[cc]{Adjusted\\ Angular\\ Distance}} & {\makecell[cc]{Mean Adjusted\\ Angular\\ Distance}} \\
    \midrule
    30    & (&48.6 & 46.8&) & 3.83 & 3.715 & (&48.6& 45&) & 3.6& 3.6   & (&48.6& 46.8&) & 3.83 & 2.55 \\
        & (&138.6& 45.0&) & 3.6 & 3.715 & (&138.6& 45&) & 3.6 & 3.6   & (&135& 43.2&) & 1.27 & 2.55 \\
    \midrule
    20    & (&48.5 & 45&) & 3.5  & 4.515 & (&48.6 & 41.4&)  & 4.45 & 5.185 & (&48.6 & 41.4&)  & 4.45  & 5.875 \\
        &  (&140.4 & 46.8&) &  5.53 & 4.515 &  (&140.4 & 48.6&) &  5.92 & 5.185 & (&142.2 & 46.8&) &  7.30 & 5.875 \\
    \midrule
     10   & (&46.8 & 46.8&)  & 2.22  & 4.9   & (&46.8 & 46.8&)  & 2.22  & 4.76  & (&48.6 & 48.6&)  & 4.45  & 4.99 \\
        &  (&142.2 & 41.4&) & 7.58 & 4.9   &  (&142.2 & 43.2&) &  7.30 & 4.76  &  (&140.4 & 43.2&) &  5.53 & 4.99 \\
    \bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%


    \begin{table*}[htbp]
    \centering
    \caption{Caption}
\begin{tabular}{c
               *3{
                 r@{}
                 S[detect-weight,table-format=3.1]@{,~}
                 S[detect-weight,table-format=2.1]
                 @{}l
                 S[table-format=1.2]
                 S[table-format=1.3]
                  }
                }
    \toprule
    & \multicolumn{6}{c}{d=0.0005} & \multicolumn{6}{c}{d=0.001} & \multicolumn{6}{c}{d=0.002} \\
    \cmidrule(r){2-7} \cmidrule(lr){8-13} \cmidrule(l){14-19}
    {SNR} & \multicolumn{4}{c}{ED} & {AAD} & {Mean AAD} & \multicolumn{4}{c}{ED} & {AAD} & {Mean AAD} &\multicolumn{4}{c}{ED} & {AAD} & {Mean AAD} \\
    \midrule
    30    & (&48.6 & 46.8&) & 3.83 & 3.715 & (&48.6& 45&) & 3.6& 3.6   & (&48.6& 46.8&) & 3.83 & 2.55 \\
        & (&138.6& 45.0&) & 3.6 & 3.715 & (&138.6& 45&) & 3.6 & 3.6   & (&135& 43.2&) & 1.27 & 2.55 \\[3pt]
    20    & (&48.5 & 45&) & 3.5  & 4.515 & (&48.6 & 41.4&)  & 4.45 & 5.185 & (&48.6 & 41.4&)  & 4.45  & 5.875 \\
        &  (&140.4 & 46.8&) &  5.53 & 4.515 &  (&140.4 & 48.6&) &  5.92 & 5.185 & (&142.2 & 46.8&) &  7.30 & 5.875 \\[3pt]
     10   & (& \ubold 46.8 &\ubold 46.8&)  & 2.22  & 4.9   & (& \ubold 46.8 & \ubold 46.8&)  & 2.22  & 4.76  & (& \ubold 48.6 & \ubold 48.6&)  & 4.45  & 4.99 \\
        &  (& \ubold 142.2 & \ubold 41.4&) & 7.58 & 4.9   &  (& \ubold 142.2 &  \ubold 43.2&) &  7.30 & 4.76  &  (& \ubold 140.4 & \ubold 43.2&) &  5.53 & 4.99 \\
    \midrule
    \multicolumn{19}{l}{ED = Estimated Direction,\quad AAD = Adjusted Angular Distance}\\
    \bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%


\end{document}

As requested in the columns, here is an excerpt of the second table without all the 'Mean AAD' columns. The code contains annotations (<------) and short descriptions of the differences compared to the above MWE.

enter image description here

\documentclass{IEEEtran}

\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}

\usepackage{etoolbox}% <-- for bold fonts
\newcommand{\ubold}{\fontseries{b}\selectfont}% <-- for bold fonts
\robustify\ubold% <-- for bold fonts

\begin{document}


    \begin{table*}[htbp]
    \centering
    \caption{Caption}
\begin{tabular}{c
               *3{
                 r@{}
                 S[detect-weight,table-format=3.1]@{,~}
                 S[detect-weight,table-format=2.1]
                 @{}l
                 S[table-format=1.2]
                 %%%S[table-format=1.3] % <---- Mean AAD columns
                  }
                }
    \toprule
    & \multicolumn{5}{c}{d=0.0005} & \multicolumn{5}{c}{d=0.001} & \multicolumn{5}{c}{d=0.002} \\ %<------------ Changed from {6} to {5}
    \cmidrule(r){2-6} \cmidrule(lr){7-11} \cmidrule(l){12-16} %<------- Changed from {2-7} to {2-6} ...
    {SNR} & \multicolumn{4}{c}{ED} & {AAD} & \multicolumn{4}{c}{ED} & {AAD}  &\multicolumn{4}{c}{ED} & {AAD}  \\ %<------ Removed {Mean AAD}
    \midrule
    30    & (&48.6 & 46.8&) & 3.83  & (&48.6& 45&) & 3.6   & (&48.6& 46.8&) & 3.83  \\ % <---------- Removed corresponding values
        & (&138.6& 45.0&) & 3.6  & (&138.6& 45&) & 3.6    & (&135& 43.2&) & 1.27  \\[3pt] % <---------- Removed corresponding values
    \midrule
    \multicolumn{16}{l}{ED = Estimated Direction,\quad AAD = Adjusted Angular Distance}\\ %<------------ Changed from {6} to {5}
    \bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%


\end{document}
7
  • This was extremely helpful, thank you leandriis. I have a follow up question for you: let's say that I want to remove every "MEAN AAD" column in your second example. How would I do that? When I try to remove the heading and associated entries, it messes up my other values. I believe the problem is that multicolumns still have the same width. How would you proceed in removing every "MEAN AAD" column? Thank you.
    – Matthew
    Jul 6, 2018 at 19:13
  • @Jake: I have edited my answer to include an example of the table without the mentioned columns. The code contains annotations to explain the changes in comparison to the original example. If there are any further questions, please feel free to ask.
    – leandriis
    Jul 6, 2018 at 19:54
  • Thank you for the quick response! In my table outputs, the estimated direction entries have a weird formatting. For coordinates with four digits, the comma separating the x and y coordinates are very close to the values. Is it possible to create more space between the comma and the coordinates? I appreciate all of your help thus far!
    – Matthew
    Jul 6, 2018 at 20:21
  • @Jake: To clarify, do you refer to numbers such as 138.6 with 'coordinates with four digits' or to something else? Did you change any of the table-format= options? This could be a reason for an overlap of the coordinates and the separating comma.
    – leandriis
    Jul 6, 2018 at 21:18
  • I did not change the format options. Yes, I am referring to numbers such as 138.6. Would I alter the table-format= options?
    – Matthew
    Jul 6, 2018 at 21:35

You must log in to answer this question.

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