2

I would like to have the table below fit on one column in a two column article environment. I was thinking to either predefine the column width or rescale the table so it fits on one column. Could someone help me with this please? Thanks in advance.

\documentclass[twoside,twocolumn,9pt]{article}
\usepackage{sectsty}
\usepackage{extsizes}
\usepackage[super,sort&compress,comma]{natbib} 
\usepackage[version=3]{mhchem}
\usepackage[left=1.5cm, right=1.5cm, top=1.785cm, bottom=2.0cm]{geometry}
\usepackage{balance}
\usepackage{mathptmx}
\usepackage{graphicx} 
\usepackage{lastpage}
\usepackage[format=plain,justification=justified,singlelinecheck=false,font={stretch=1.125,small,sf},labelfont=bf,labelsep=space]{caption}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage{fnpos}
\usepackage[english]{babel}
\addto{\captionsenglish}{%
 \renewcommand{\refname}{References}
}
\usepackage{array}
\usepackage{droidsans}
\usepackage{charter}
\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{setspace}
\usepackage[compact]{titlesec}
\usepackage{hyperref}

\usepackage{amsmath}
\usepackage{subfig}
\usepackage{siunitx}
\usepackage{media9}%
%Define extra SI units
\DeclareSIUnit\bar{bar}
\DeclareSIUnit\mAh{mAh}
\usepackage{textcomp}

\usepackage{chemformula}

\usepackage{IEEEtrantools}
\begin{document}
\begin{table}[!h]
\centering
\small
\caption{Caption1.}
\label{table1}
  \begin{tabular*}{0.9\textwidth}{@{\extracolsep{\fill}}l|cccccc}
    \hline
    \textbf{Column1}  & \textbf{Column 2} & \textbf{Column 3} & \textbf{$N_{\text{column4}}$} & \textbf{$N_{\text{column5}}$} & \textbf{$N_{\text{column6}}$} & \textbf{$N_{column7}}$} \\
    \hline
    BLA     & 1.0 & 1:6       & 78  & 468 & --  & 546  \\
            & 3.0 & 1:2       & 183 & 366 & --  & 549  \\
    \hline
    BLABLAA & 1.0 & 1:1.2:2.2 & 125 & 150 & 275 & 550  \\
            & 1.2 & 1:1.2:1.6 & 145 & 174 & 232 & 551  \\
            & 1.5 & 1:1.2:1.2 & 172 & 172 & 206 & 550  \\
            & 2.0 & 1:0.7:0.9 & 212 & 148 & 191 & 551  \\
            & 3.0 & 1:0.5:0.6 & 262 & 131 & 157 & 550  \\
    \hline        
    BLABLAA & 1.0 & 1:1.2:2.4 & 120 & 144 & 288 & 552  \\
            & 1.2 & 1:1.2:1.8 & 138 & 166 & 288 & 552  \\
            & 1.5 & 1:1.2:1.4 & 162 & 162 & 227 & 551  \\
            & 2.0 & 1:0.8:1.0 & 196 & 157 & 196 & 549  \\
            & 3.0 & 1:0.5:0.7 & 250 & 125 & 175 & 550  \\
    \hline
  \end{tabular*}
\end{table}
\end{document}

John

3
  • You have error in the first table row. Also it is not clear how the last three column headers (\textbf{$N_{\text{column4}}$}) should looks. Your table seems to be to wide that can be fit in one column (you may consider use smaller font size in table as well reduce distance between columns (define smaller \tabcolsep). It be helpful, if you add preamble to your code fragment :-)
    – Zarko
    Jul 27, 2022 at 14:42
  • I've added the preamble now. I do not get the error in the first table row? Where should I specify the \tabcolsep ? Jul 27, 2022 at 14:49
  • See my answer. There I try to explain problems with your table and show possible solutions
    – Zarko
    Jul 27, 2022 at 15:47

4 Answers 4

1

too long for the comment section:

  • your table is too wide even after one replaces the incorrect use of \textwidth with \columnwidth (or \linewidth). However, I would rather use simple tabular environment and smaller font size (\footnotesize) in it
  • The last column header has a syntax error. Instead of \textbf{$N_{column7}}$} probably should be \textbf{$N_{\text{column7}}$}
  • to have readable table, I suggest you to use some abbreviation for column headers
\documentclass[twoside,twocolumn]{article}
\usepackage{extsizes}
\usepackage{lipsum} % <--- for dummy text filler

\begin{document}
\lipsum[1]
\begin{table}[ht]
\centering
\footnotesize
\caption{Caption1.}
\setlength\tabcolsep{3pt}  % <---
\label{table1}
  \begin{tabular}{@{} l*{6}{c} @{}}
    \hline
\textbf{Col. 1} & \textbf{Col. 2}   & \textbf{Col.l 3}  & \textbf{Col. 4} 
                & \textbf{Col. 5}   & \textbf{Col.l 6}  & \textbf{Col. 7}   \\
    \hline
    BLA     & 1.0 & 1:6       & 78  & 468 & --  & 546  \\
            & 3.0 & 1:2       & 183 & 366 & --  & 549  \\
    \hline
    BLABLAA & 1.0 & 1:1.2:2.2 & 125 & 150 & 275 & 550  \\
            & 1.2 & 1:1.2:1.6 & 145 & 174 & 232 & 551  \\
            & 1.5 & 1:1.2:1.2 & 172 & 172 & 206 & 550  \\
            & 2.0 & 1:0.7:0.9 & 212 & 148 & 191 & 551  \\
            & 3.0 & 1:0.5:0.6 & 262 & 131 & 157 & 550  \\
    \hline
    BLABLAA & 1.0 & 1:1.2:2.4 & 120 & 144 & 288 & 552  \\
            & 1.2 & 1:1.2:1.8 & 138 & 166 & 288 & 552  \\
            & 1.5 & 1:1.2:1.4 & 162 & 162 & 227 & 551  \\
            & 2.0 & 1:0.8:1.0 & 196 & 157 & 196 & 549  \\
            & 3.0 & 1:0.5:0.7 & 250 & 125 & 175 & 550  \\
    \hline
  \end{tabular}
\end{table}
\lipsum[2-7]
\end{document}

enter image description here

Another option is to write table across two columns with

\begin{table*}
\centering
\begin{tabular}{<column specification}
% table 
\end{tabular}
\end{table*}

Table will appear at top of the next page after its insertion.

Edit: Considered is @Mico comment

Addendum: For point you to another possibility how to write your table by use of the tabularray package:

\documentclass[twoside,twocolumn, 9pt]{article}
\usepackage{extsizes}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs}

\usepackage{lipsum} % <--- for dummy text filler


\begin{document}
\lipsum[1]

\begin{table}[ht]
\footnotesize
\caption{Caption1.}
\label{table1}
  \begin{tblr}{colsep=3pt,
               colspec = {@{} l Q[c] X[c] *{4}{X[c, $]} @{}},
               row{1} = {4-7}{mode=math}
               }
    \toprule
Col. 1  & Col. 2            & Col.l 3           & Col. 4 
        & N_{\text{col5}}   & N_{\text{col6}}   & N_{\text{col7}}   \\
    \midrule
    BLA     & 1.0   & 1:6   &  78   & 468   & --  & 546   \\
            & 3.0   & 1:2   & 183   & 366   & --  & 549   \\
    \midrule
    BLABLAA & 1.0 & 1:1.2:2.2 & 125 & 150   & 275 & 550   \\
            & 1.2 & 1:1.2:1.6 & 145 & 174   & 232 & 551   \\
            & 1.5 & 1:1.2:1.2 & 172 & 172   & 206 & 550   \\
            & 2.0 & 1:0.7:0.9 & 212 & 148   & 191 & 551   \\
            & 3.0 & 1:0.5:0.6 & 262 & 131   & 157 & 550   \\
    \midrule
    BLABLAA & 1.0 & 1:1.2:2.4 & 120 & 144   & 288 & 552   \\
            & 1.2 & 1:1.2:1.8 & 138 & 166   & 288 & 552   \\
            & 1.5 & 1:0.5:0.7 & 250 & 125 & 175 & 550   \\
    \bottomrule
  \end{tblr}
\end{table}
\lipsum[2-7]
\end{document}

enter image description here

3
  • The document class option 9pt works because the OP loads the extsizes package.
    – Mico
    Jul 27, 2022 at 15:57
  • 1
    @Mico, I overlooked this. Actually, I wrote answer before OP provide preamble. I will correct this ASAp.
    – Zarko
    Jul 27, 2022 at 16:06
  • 1
    @Mico, thank you very much for editing my answer.
    – Zarko
    Jul 27, 2022 at 18:20
2

In addition to fixing a syntax error in the header row, I suggest you

  • abbreviate some of the text in the header cells

  • set the target width of the tabular* environment to \columnwidth instead of 0.9\textwidth

  • set the length parameter \tabcolsep to 0pt (default value: 6pt) and let LaTeX figure out how much intercolumn whitespace padding is possible

  • get rid of the redundant \centering instruction and drop the \small instruction

Three additional comments:

  • Never use vertical rules in a tabular* environment. And do replace \hline with the well-spaced macros of the booktabs package: \toprule, \midrule, \addlinespace, and \bottomrule.

  • Don't use bold-facing needlessly unless you want to come across to your readers as a person who likes to shout at their readers. For sure, the table's header row works perfectly well without bold-facing.

  • I'd drop the \usepackage{mathptmx} instruction in the preamble since it gets clobbered later on by the \usepackage{charter} instruction.

enter image description here

\documentclass[twocolumn,twosided,9pt]{article}
\usepackage{sectsty}
\usepackage{extsizes}
\usepackage[super,sort&compress,comma]{natbib} 
\usepackage[version=3]{mhchem} % don't you want 'version=4'?
\usepackage[left=1.5cm, right=1.5cm, top=1.785cm, bottom=2.0cm]{geometry}
\usepackage{balance}
%%%\usepackage{mathptmx} % this command gets clobbered later
\usepackage{graphicx} 
\usepackage{lastpage}
\usepackage[format=plain,%justification=justified,
            singlelinecheck=false,
            font={stretch=1.125,small,sf},
            labelfont=bf,
            labelsep=space]{caption}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage{fnpos}
\usepackage[english]{babel}
\addto{\captionsenglish}{%
 \renewcommand{\refname}{References}
}
\usepackage{array}

\usepackage{droidsans}
\usepackage{charter}
\usepackage[T1]{fontenc}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{setspace}
\usepackage[compact]{titlesec}
\usepackage{hyperref}

%from line below the packages have been added by Wessel van Ekeren
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{siunitx}
\usepackage{media9}%
%Define extra SI units
\DeclareSIUnit\bar{bar}
\DeclareSIUnit\mAh{mAh}
\usepackage{textcomp}
\usepackage{chemformula}
\usepackage{IEEEtrantools}

%% new:
\usepackage{lipsum}
\usepackage{booktabs} % for well-spaced horizontal lines

\begin{document}
\begin{table}[!h]
%\centering % <-- redundant
\setlength\tabcolsep{0pt} % <-- make LaTeX figure out intercol whitespace padding
%\small % <-- not needed
\caption{Caption1.}
\label{table1}
% use '\columnwidth' as the target width of 'tabular*' env.:
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} l cc cccc }
    \toprule
    Col 1  & Col 2 & Col 3 & $N_{\text{col4}}$ & $N_{\text{col5}}$ & $N_{\text{col6}}$ & $N_{\text{col7}}$ \\
    \midrule
    BLA     & 1.0 & 1:6       & 78  & 468 & --  & 546  \\
            & 3.0 & 1:2       & 183 & 366 & --  & 549  \\
    \addlinespace
    BLABLAA & 1.0 & 1:1.2:2.2 & 125 & 150 & 275 & 550  \\
            & 1.2 & 1:1.2:1.6 & 145 & 174 & 232 & 551  \\
            & 1.5 & 1:1.2:1.2 & 172 & 172 & 206 & 550  \\
            & 2.0 & 1:0.7:0.9 & 212 & 148 & 191 & 551  \\
            & 3.0 & 1:0.5:0.6 & 262 & 131 & 157 & 550  \\
    \addlinespace        
    BLABLAA & 1.0 & 1:1.2:2.4 & 120 & 144 & 288 & 552  \\
            & 1.2 & 1:1.2:1.8 & 138 & 166 & 288 & 552  \\
            & 1.5 & 1:1.2:1.4 & 162 & 162 & 227 & 551  \\
            & 2.0 & 1:0.8:1.0 & 196 & 157 & 196 & 549  \\
            & 3.0 & 1:0.5:0.7 & 250 & 125 & 175 & 550  \\
    \bottomrule
\end{tabular*}
\end{table}

\lipsum[2] % filler text
\end{document}
2

Avoid repetitions in tables. Apart from reducing spacing, it's also a good practice. For instance, Column X or N column X can just be in an extra row and serve as sub-headings, while lower row would contain additional indices. The table I present is probably not exactly what you had in question but hopefully can give you some ideas

EDIT. Thanks to Mico and the comments on missing packages.
After applying settings from the original code, I realised the table doesn't need to be of the full column width. In that case, however, the left-aligned caption would not be in line with the table. If that effect is desired, the table can be put inside threeparttable

enter image description here

\documentclass[twoside,twocolumn,9pt]{extarticle}
\usepackage[left=1.5cm, right=1.5cm, top=1.785cm, bottom=2.0cm]{geometry}
\usepackage[compact]{titlesec}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{array}
\usepackage{threeparttable}
\usepackage{charter}
% \usepackage{sectsty}
\usepackage[super,sort&compress,comma]{natbib}
\usepackage[version=3]{mhchem}
\usepackage{chemformula}
\usepackage{balance}
\usepackage{mathptmx}
% \usepackage{graphicx} 
\usepackage{lastpage}
\usepackage[format=plain,justification=justified,singlelinecheck=false,font={stretch=1.125,small,sf},labelfont=bf,labelsep=space]{caption}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage{fnpos}
\usepackage[english]{babel}
\usepackage{droidsans}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
%from line below the packages have been added by Wessel van Ekeren
\usepackage{subfig}
\usepackage{media9}%
\usepackage{siunitx}
\usepackage{textcomp}

% Define extra SI units
    \DeclareSIUnit\bar{bar}
    \DeclareSIUnit\mAh{mAh}

\addto{\captionsenglish}{%
    \renewcommand{\refname}{References}}

\usepackage{booktabs}
\usepackage{bm}
\usepackage{kantlipsum}


\begin{document}
\kant[1]
\begin{table}[tbh]
    \small
    \centering
    \setlength\tabcolsep{0pt}
    \begin{threeparttable}
        \caption{Caption1.}
        \label{table1}
        \begin{tabular*}{0.8\linewidth}{
                l @{\extracolsep{\fill}}
                *2{wc{1cm}}
                *4{S[table-format=3.0]}
            }
            \toprule
            & \multicolumn{2}{c}{\textbf{Columns \textit{x}}}
            & \multicolumn{4}{c}{\(\bm{N}_\textbf{column \itshape x}\)} \\
            \cmidrule{2-3}\cmidrule{4-7}
            \multicolumn{1}{r}{\textbf{\textit{x}:}} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4}  & \textbf{5}  & \textbf{6} \\ 
            \midrule[\heavyrulewidth]
            BLA     & 1.0 & 1:6       & 78  & 468 & {--}  & 546  \\
                    & 3.0 & 1:2       & 183 & 366 & {--}  & 549  \\
            \midrule
            BLABLAA & 1.0 & 1:1.2:2.2 & 125 & 150 & 275 & 550  \\
                    & 1.2 & 1:1.2:1.6 & 145 & 174 & 232 & 551  \\
                    & 1.5 & 1:1.2:1.2 & 172 & 172 & 206 & 550  \\
                    & 2.0 & 1:0.7:0.9 & 212 & 148 & 191 & 551  \\
                    & 3.0 & 1:0.5:0.6 & 262 & 131 & 157 & 550  \\
            \midrule
            BLABLAA & 1.0 & 1:1.2:2.4 & 120 & 144 & 288 & 552  \\
                    & 1.2 & 1:1.2:1.8 & 138 & 166 & 288 & 552  \\
                    & 1.5 & 1:1.2:1.4 & 162 & 162 & 227 & 551  \\
                    & 2.0 & 1:0.8:1.0 & 196 & 157 & 196 & 549  \\
                    & 3.0 & 1:0.5:0.7 & 250 & 125 & 175 & 550  \\
            \bottomrule
        \end{tabular*}
    \end{threeparttable}
\end{table}

\kant
\end{document}
2
  • Why did you suppress the 9pt document class option and drop loading the extsizes and charter packages?
    – Mico
    Jul 27, 2022 at 15:58
  • 1
    I see what you mean. I was not aware extsizes provides support for additional font sizes. I'll correct the answer and include it in the code. Thanks
    – Celdor
    Jul 27, 2022 at 16:08
0

You need to use \linewidth instead of \textwidth. It looks the latter gives whole page width instead of one column width.

\begin{document}

\begin{table}[!h]
    \centering
    \tiny
    \caption{Caption1.}
    \label{table1}
    \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l|cccccc}
        \hline
        \textbf{Column1}  & \textbf{Column 2} & \textbf{Column 3} & \textbf{$N_{\text{column4}}$} & \textbf{$N_{\text{column5}}$} & \textbf{$N_{\text{column6}}$} & \textbf{$N_{column7}$} \\
    \hline
    BLA     & 1.0 & 1:6       & 78  & 468 & --  & 546  \\
    & 3.0 & 1:2       & 183 & 366 & --  & 549  \\
    \hline
    BLABLAA & 1.0 & 1:1.2:2.2 & 125 & 150 & 275 & 550  \\
    & 1.2 & 1:1.2:1.6 & 145 & 174 & 232 & 551  \\
    & 1.5 & 1:1.2:1.2 & 172 & 172 & 206 & 550  \\
    & 2.0 & 1:0.7:0.9 & 212 & 148 & 191 & 551  \\
    & 3.0 & 1:0.5:0.6 & 262 & 131 & 157 & 550  \\
    \hline        
    BLABLAA & 1.0 & 1:1.2:2.4 & 120 & 144 & 288 & 552  \\
    & 1.2 & 1:1.2:1.8 & 138 & 166 & 288 & 552  \\
    & 1.5 & 1:1.2:1.4 & 162 & 162 & 227 & 551  \\
    & 2.0 & 1:0.8:1.0 & 196 & 157 & 196 & 549  \\
    & 3.0 & 1:0.5:0.7 & 250 & 125 & 175 & 550  \\
    \hline
\end{tabular*}
\end{table}
\end{document}

Also \small is too big for one-column table, it needs to use \tiny to fit the table within a column width.

here you get

1
  • It wouldn't be necessary to employ \tiny if one were to make the header cells less verbose and/or reduced the value of \tabcolsep. The default value of this parameter is 6pt. Since a tabular* environment is used along with the @{\extracolsep{\fill}} spacing directive, one can even set \setlength\tabcolsep{0pt} and let LaTeX work out what's available in terms of intercolumn whitespace padding. A separate (though minor) issue: Since the tabular* environment is set to occupy a width of \linewidth, the \centering instruction is redundant.
    – Mico
    Jul 27, 2022 at 16:59

You must log in to answer this question.

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