1

Can not restrict the table

\documentclass[pdflatex, sn-aps]{sn-jnl}% American Physical Society (APS) Reference Style
%%%% Standard Packages
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{comment}
\usepackage[center]{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[misc]{ifsym}
\usepackage{csquotes}
\usepackage[section]{placeins}
\usepackage{siunitx}
%%<additional latex packages if required can be included here>
\usepackage{amsmath}
\usepackage{graphicx}
\graphicspath{{./images/}}
%Table packages
\usepackage[figuresright]{rotating}
\setlength{\rotFPtop}{0pt plus 1fil}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand{\theadfont}{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}

\raggedbottom %%\unnumbered% uncomment this for unnumbered level heads

\begin{document} \begin{table} \centering % table caption is above the table \caption{Part of the patient data collected via the questionnaire} \label{tab:Patient data} % Give a unique label % For LaTeX tables use \begin{tabular} { c c c c c c c c c } \toprule \thead{Patient\Number} &\thead{$T_{before}$\(week1)} & \thead{$T_{after}$\(week1)}& \thead{$C_{week1}$} & \thead{$C_{week2}$}& \thead{$C_{week3}$}& \thead{$C_{week4}$}& \thead{Overall\improvement}&\thead{$T_{after}$\(week4)}\ \midrule\ 1&41&34&17.07&17.26&20.62&23.67&6.60&32 \ \addlinespace 2&41&41&0.00&3.49&6.47&7.16&7.16&35 \ \addlinespace 3&41&34&17.07&18.88&19.87&21.12&4.05&30 \ \addlinespace 4&89&88&1.12&3.27&6.13&8.30&7.18&81 \ \addlinespace 12&50&50&0.00&0.00&0.00&0.00&0.00&50 \ \bottomrule \end{tabular} \end{table} \end{document}

Output

Bukaida
  • 617
  • 1
    see https://tex.stackexchange.com/q/332902/1090 – David Carlisle Jan 26 '22 at 09:44
  • Too geeky for a beginner like me – Bukaida Jan 26 '22 at 09:48
  • 1
    sorry that's how the site works. If you try something and get an error you could ask a more specific question about the error you get, but generic table-too-wide questions can't really have any new answers. Just put \footnotesize before the \begin{tabular} so it is smaller. – David Carlisle Jan 26 '22 at 09:50
  • You could also change environment from tabular to tabular* and add "forced" width, with flexible spaces between columns (see this page), as an example the definition could be: \begin{tabular*}{\linewidth}{c @{\extracolsep{\fill}} c c c c c c c c} ... \end{tabular*}. But your table will be too narrow and probably will not look well. – Celdor Jan 26 '22 at 10:13
  • Adding \footnotesize before \begin{tabular} had no effect on the output. – Bukaida Jan 26 '22 at 10:46
  • Temporarily adjusted by shortening the headings. – Bukaida Jan 26 '22 at 10:56
  • @Celdor Thank you for mentioning exactly where to start. – Bukaida Jan 26 '22 at 11:36
  • @Bukaida Np. You may also need to add \setlength{\tabcolsep}{0pt} before the tabular/tabular* environment. BTW adding \footnotesize as David mentioned sets smaller font inside a table and it should work. – Celdor Jan 26 '22 at 11:47
  • @Bukaida If creating tables are a pain for you, you can try this tool: https://www.latex-tables.com/ – Terrarium Jan 26 '22 at 13:06

1 Answers1

0

I suggest you shorten the header entries (e.g., by abbreviating "week" as "wk", using roman rather than math-italic lettering, and not over-using bold lettering), use \setlength\tabcolsep{0pt}, and employ a tabular* environment. That way, you won't even to employ \footnotesize. Oh, and I would use the S column type for 5 of the 9 columns in the table.

enter image description here

\documentclass[sn-aps]{sn-jnl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{comment}
\usepackage[center]{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[misc]{ifsym}
\usepackage{csquotes}
\usepackage[section]{placeins}
\usepackage{siunitx} % for 'S' column type

\usepackage{amsmath} \usepackage{graphicx} \graphicspath{{./images/}}

\usepackage[figuresright]{rotating} \setlength{\rotFPtop}{0pt plus 1fil} \usepackage{booktabs, makecell, multirow, tabularx} \renewcommand{\theadfont}{\normalfont} \renewcommand\theadgape{} \newcolumntype{L}{>{\raggedright\arraybackslash}X} \newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}} \raggedbottom

\begin{document} \begin{table} \setlength\tabcolsep{0pt} % let LaTeX figure out amount of intercolumn whitespace \caption{Part of patient data collected via questionnaire} \label{tab:Patient data}
\begin{tabular}{\textwidth}{@{\extracolsep{\fill}} S[table-format=2.0] cc {4}{S[table-format=2.2]} cc } \toprule {\thead{Patient\Number}} & \thead{$T_{\textrm{before}}$ \(wk1)} & \thead{$T_{\textrm{after}}$ \(wk1)}& $C_{\textrm{wk1}}$& $C_{\textrm{wk2}}$& $C_{\textrm{wk3}}$& $C_{\textrm{wk4}}$& \thead{Overall\improve't}& \thead{$T_{\textrm{after}}$ \(wk4)}\ \midrule 1 &41&34&17.07&17.26&20.62&23.67&6.60&32 \ 2 &41&41& 0.00& 3.49& 6.47& 7.16&7.16&35 \ 3 &41&34&17.07&18.88&19.87&21.12&4.05&30 \ 4 &89&88& 1.12& 3.27& 6.13& 8.30&7.18&81 \ 12&50&50& 0.00& 0.00& 0.00& 0.00&0.00&50 \ \bottomrule \end{tabular*} \end{table} \end{document}

Mico
  • 506,678
  • OP has slightly larger vertical spaces between rows. It would be worth adding redefinition of the arraystretch to achieve the similar effect. – Celdor Jan 26 '22 at 12:02
  • Thanks Mico. Although I managed to shorten the table following Celdor's suggestions but was struggling with the headers. This one is quite neat. Thanks to both of you. – Bukaida Jan 26 '22 at 12:15
  • @Celdor - Thanks. Indeed, I removed all of the \addlinespace directives that were in the OP's code. I agree with you that increasing the value of \arraystretch is the way to go if the spacing between every single line should be increased. – Mico Jan 26 '22 at 13:16