2

Update: this problem does not appear when using

\documentclass[twocolumn]{article}

However, I use \documentclass[twocolumn]{aastex61} which can be found at http://journals.aas.org/authors/aastex/aastex61.cls. What is in the aastex61.cls file that is causing this?

I am writing a two-column research article, and I have a table in it. I wanted the table to take the maximum space in the article column, so that it is readable. I used \resizebox{\columnwidth}{!} to give it the command to expand on the full width of the column (and the ! to keep the height scaled), as described in other answers on tex.stackexchange, like Resizing a table by textheight or in the wikibooks documentation https://en.wikibooks.org/wiki/LaTeX/Tables.

So I run the following code

\documentclass[twocolumn]{aastex61}
\usepackage{color} 
\usepackage{lipsum}
\usepackage{mathtools}
\usepackage{placeins}
\usepackage{multirow}
\usepackage{float}
\usepackage{silence}

\begin{document}

\begin{abstract}
\lipsum[1-1]
\end{abstract}


\section{Introduction}
\lipsum[1]
\begin{table}[h!]
\centering
\resizebox{\columnwidth}{!}{%
\begin{tabular}{|l|l|l|l|l|l|l|}
\multicolumn{2}{|l|}{WC coefficient for PC number}    & WC1 & WC2 & WC3 & WC4 & WC5 \\
\multirow{4}{*}{Fixed radiation field}     & Using 2 PCs &     &     &     &     & \\
& Using 3 PCs &     &     &     &     &     \\ 
& Using 4 PCs &     &     &     &     &     \\ 
& Using 5 PCs &     &     &     &     &     \\ \hline
\multicolumn{1}{|l|}{\multirow{4}{*}{Variable radiation field}} & Using 2 PCs &     &     &     &     &     \\
\multicolumn{1}{|l|}{} & Using 3 PCs &     &     &     &     &     \\
\multicolumn{1}{|l|}{} & Using 4 PCs &     &     &     &     &     \\
\multicolumn{1}{|l|}{} & Using 5 PCs &     &     &     &     &     \\
\end{tabular}%
}
\caption{Initial Values for the PCA coefficients}
\label{PCA_initial}
\end{table}
\lipsum[2-3]
\end{document}

However, the table is pushed to the right compared to the other text in the article column. See this picture:

enter image description here

This document explains how using @{} before the first column marker is supposed to empty the space before the first column and aligned with the exterior text. https://www.tug.org/TUGboat/tb28-3/tb90hoeppner.pdf I tried using that, and it had no effect.

I also tried using the @{\hspace{-1cm}) as described here https://en.wikibooks.org/wiki/LaTeX/Tables#Aligning_columns_at_decimal_points_using_dcolumn The border does move left, but the horizontal line gets interrupted and I obtain

enter image description here

The only time when I got the table to be aligned with the rest of the article text was when I removed the "table" wrapper, and left the "tabular" only. But this of course fixed the table in the text (it cannot float), and does not allow me to reference it and caption it.

What are some solutions?

4
  • As is, the code fragment you gave requires a few extra packages. A small document with those packages added gives the result you seem to expect
    – remco
    Commented Mar 16, 2018 at 17:08
  • What are those packages? (I added now in the code descriptions all the packages I am using) Commented Mar 16, 2018 at 18:10
  • your example still can not be used. Try doing what you are asking others to do copy the text from the example above and run through latex: it makes multiple errors starting with ! LaTeX Error: Missing \begin{document}. Commented Mar 16, 2018 at 20:17
  • Done. I was not intending originally for that to be a copy-and-paste thing, but I can see the use. Commented Mar 16, 2018 at 21:02

2 Answers 2

1

You can get a much better table by removing redundant information and sectioning the it.

\documentclass[twocolumn]{aastex61}

\usepackage{booktabs}

\usepackage{lipsum}

\begin{document}

\begin{abstract}
\lipsum[1-1]
\end{abstract}


\section{Introduction}

\lipsum[1]

\begin{table}[htp!]
\renewcommand\arraystretch{1} % aastex sets it to 1.2, why? :-(
\centering
\begin{tabular}{ @{} l *{5}{c} @{} }
\toprule
PCs & \multicolumn{5}{c@{}}{WC coefficient for PC number} \\
\cmidrule(l){2-6}
& WC1 & WC2 & WC3 & WC4 & WC5 \\
\midrule
\multicolumn{6}{@{}l@{}}{\textit{Fixed radiation field}} \\
2 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
3 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\ 
4 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\ 
5 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
\midrule
\multicolumn{6}{@{}l@{}}{\textit{Variable radiation field}} \\
2 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
3 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
4 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
5 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
\bottomrule
\end{tabular}

\caption{Initial Values for the PCA coefficients}
\label{PCA_initial}
\end{table}

\lipsum[2-3]

\end{document}

enter image description here

If you use tabular* as follows

\begin{tabular*}{\columnwidth}{ @{\extracolsep{\fill}} l *{5}{c} @{} }
\toprule
PCs & \multicolumn{5}{c@{}}{WC coefficient for PC number} \\
\cmidrule(l){2-6}
& WC1 & WC2 & WC3 & WC4 & WC5 \\
\midrule
\multicolumn{6}{@{}l@{}}{\textit{Fixed radiation field}} \\
2 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
3 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
4 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
5 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
\midrule
\multicolumn{6}{@{}l@{}}{\textit{Variable radiation field}} \\
2 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
3 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
4 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
5 & 12.34 & 12.34 & 12.34 & 12.34 & 12.34 \\
\bottomrule
\end{tabular*}

then the table will fill the whole column width.

enter image description here

4
  • Yes, indeed, that looks much better. However, it is still not aligned with the text of the article, on the left. Commented Mar 16, 2018 at 22:55
  • @IoanaZelko I added how to make the table to span the whole column width. I don't think it's necessary, though.
    – egreg
    Commented Mar 16, 2018 at 22:57
  • That is great. Is it the command @{\extracolsep{\fill}} that does the job? and it requires tabular* ? How did you know to move to it? Commented Mar 16, 2018 at 23:28
  • @IoanaZelko I've been using LaTeX for almost 25 years. ;-)
    – egreg
    Commented Mar 16, 2018 at 23:30
0

Don't use \resizebox for this: it leads to inconsistent font size, and very often, the tables get unreadable.

It is better to play with the font size if necessary (not too small, though), intercolumn spacing, and possible multiline cells with the makecell package. In addition, I removed vertical rules, using some of the horizontal rules defined in booktabs for a more professional look:

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{multirow, makecell, booktabs}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{table}[h!]
\centering \setlength{\tabcolsep}{3.5pt}
\renewcommand{\cellalign}{lc}
\begin{tabular}{@{}l|*{6}{l}@{}}
\toprule
\multicolumn{2}{r}{\makecell[r]{WC coefficient for \\PC number}} & WC1 & WC2 & WC3 & WC4 & WC5 \\
\midrule
\multicolumn{1}{c}{} & Using\\
\addlinespace
\multirowcell{4}{Fixed \\radiation\\ field} & 2 PCs & & & & & \\
& 3 PCs & & & & & \\
& 4 PCs & & & & & \\
& 5 PCs & & & & & \\
\addlinespace[2ex]
\multirowcell{4}{Variable\\ radiation\\ field} & 2 PCs & & & & & \\
& 3 PCs & & & & & \\
& 4 PCs & & & & & \\
& 5 PCs & & & & & \\
\bottomrule
\end{tabular}%
%}
\caption{Initial Values for the PCA coefficients}
\label{PCA_initial}
\end{table}

\lipsum[2-3]

\end{document} 

enter image description here

Edit :

It seems makecell doesn't work well with the aastex class. As a workaround, here is a variant code, with some parameters found by trial and error which yields the same result:

    \documentclass[twocolumn]{aastex6}%
    \usepackage{graphicx}
    \usepackage{multirow, booktabs}
    \usepackage{lipsum}

    \begin{document}

    \lipsum[1]

    \begin{table}[h!]
    \centering %
    \begin{tabular}{@{}r|l*{5}{l}@{}}
    \toprule
    \multicolumn{2}{p{28mm}}{\raggedleft{WC coefficient for PC number}} & WC1 & WC2 & WC3 & WC4 & WC5 \\
   \midrule
    \multicolumn{1}{c}{} & Using\\
    \addlinespace
    \multirow{4}{15mm}{\raggedleft Fixed radiation field} & 2 PCs & & & & & \\%
    & 3 PCs & & & & & \\
    & 4 PCs & & & & & \\
    & 5 PCs & & & & & \\
    \addlinespace[2ex]
    \multirow{4}{15mm}{\raggedleft Variable radiation field} & 2 PCs & & & & & \\%\\
    & 3 PCs & & & & & \\
    & 4 PCs & & & & & \\
    & 5 PCs & & & & & \\
    \bottomrule
 %\hline
    \end{tabular}%
    %}
    \caption{Initial Values for the PCA coefficients}
    \label{PCA_initial}
    \end{table}

    \lipsum[2-9]

    \end{document} 
3
  • This looks much better than mine. However, it seems that if I use the aastex.cls file, the left alignment does not happen. Commented Mar 16, 2018 at 22:56
  • @IoanaZelko: There seems to be some coflict between makecell and the aastex class (for me, it is aastex6.cls). I've posted a workaround.
    – Bernard
    Commented Mar 17, 2018 at 0:13
  • Got it! Looks good now. Commented Mar 17, 2018 at 1:00

You must log in to answer this question.

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