3

Requesting help... Dear all, I have 2 questions if you could please help solve.

(1) Would anyone please be able to let me know a way to get this table within the margins of the document? Right now, the heading of the second column seems too wide. May be if you can suggest a way that I can shrink the header for the second column down to two lines, it might work. Please see image 1 attached. I have used the following code (please see the code below):

Image (1) - second column too wide

\begin{table}[H]
   \caption{Summary of gene inputs and pathway outputs for pathway analysis of the isografts}
   \small
   \centering
    \begin{tabular}{lllp{\dimexpr 0.65\linewidth-8\tabcolsep}}
   \toprule[\heavyrulewidth]\toprule[\heavyrulewidth]
   \textbf{Timepoint comparison} & \textbf{Total number of input genes (P < 0.01)} & \textbf{Pathway outputs} & \textbf{Number of statistically significant enriched pathways (P < 0.05)}\\ 
   \midrule
T0-T1g downregulated & 2308 & Immunological & 0\\
& & Inflammatory & 2 \\
T0-T1g upregulated & 2187 & Immunological & 14 \\
& & Inflammatory & 28 \\
T1g-T7g downregulated & 2034 & Immunological & 1\\
& & Inflammatory & 15 \\
T1g-T7g upregulated & 1897 & Immunological & 1\\
& & Inflammatory & 2 \\
T7g-T30g downregulated & 1360 & Immunological & 3\\
& & Inflammatory & 2 \\
T7g-T30g upregulated & 751 & Immunological & 4\\
& & Inflammatory & 8 \\\hdashline
   \bottomrule[\heavyrulewidth] 
   \end{tabular}
\end{table}

(2) Similar issue as the previous table, except this time, the header of the second column is in two lines, but doesn't align with the rest of the column. Would anyone please be able to let me know a way to align the header with rest of the content in the column? Please see image 2 attached.I have used the following code (please see the code below):

Image (2) - second column header and content misaligned

\begin{table}[H]
\setlength{\tabcolsep}{2.5pt}
   \caption{Serum markers in the allograft recipients with no significant difference in concentrations between timepoints}
   \small
    \centering
   \begin{tabular}{ l p{\dimexpr 0.65\linewidth-2\tabcolsep}}
   \toprule[\heavyrulewidth]\toprule[\heavyrulewidth]
   \textbf{Serum marker} & \textbf{\makecell {Limit of Detection (LOD)\\(pg/mL)}}\\ 
   \midrule
1.  AR (amphiregulin) & 13.6\\ 
2.  B7-1 (CD80) & 35.3\\ 
3.  BAFF-R (B cell activating factor receptor)  & 7.7\\ 
4.  BTC (betacellulin)  & 5.7\\ 
5.  C5a (complement C5 alpha chain) & 1.7\\ 
6.  CCL6    (C-C motif chemokine 6) & 23.2\\ 
7.  CD6 (T cell differentiation antigen 6)  & 2.5\\ 
8.  CX3CL1 (Fractalkine)    & 2016.3\\ 
32. Marapsin & 77.7\\\hdashline
   \bottomrule[\heavyrulewidth] 
   \end{tabular}
\end{table}

Please see the following details about some parameters I have used for the code as it may help;

\documentclass[12pt, a4paper]{report}
\input{Packages.tex} included the following;

    % For tables
    \usepackage{threeparttable}
    \usepackage{threeparttablex}
    \usepackage{ctable}
    \usepackage{tabularx}
    \usepackage{rotating}
    \usepackage{makecell}
    \usepackage{longtable}
    
    % other
    \usepackage[T1]{fontenc}
    \usepackage[latin1]{inputenc}
    \usepackage[english]{babel}
    \usepackage{siunitx}
    \usepackage{graphicx}
    \usepackage{tipa} % for the \ark{} command
    \usepackage{graphics} % for pdf, bitmapped graphics files
    \usepackage{times} % assumes new font selection scheme installed
    \usepackage{amsmath}
    \usepackage{latexsym}
    \usepackage{amscd}% for commutative diagrams
    \usepackage{mathrsfs} %this package is for the script font \mathscr
    \usepackage{relsize}
    \usepackage{delarray}
    \usepackage{pstricks}
    \usepackage{theorem}
    \usepackage{changepage}
    \usepackage{euscript}
    \usepackage{textcomp}
    \usepackage{esvect}
    \usepackage{parskip}
    \usepackage{placeins}
    \usepackage{subfigure}
18
  • 1
    (1) You could perhaps change the header of the second table by \begin{tabular}{c} \textbf{Total number of}\\ \textbf{input genes (P < 0.01)} \end{tabular} Commented Mar 28, 2022 at 5:11
  • 1
    For the first question, use ` \thead` tpo enable line breaks in the headers. For the second question, about the alignment, use \makecell[l]{…} or \thead[l] since by default it is centred, both horizontally and vertically. Also, note that bydefaul thead fontsize is \footnotesize, so if you do not want it, you have to redefine \theadfont`.
    – Bernard
    Commented Mar 28, 2022 at 5:36
  • 1
    Regarding the column header in table 1: Table 2 already contains a header that is split into two rows. Why not adapt this method to the header in table 1 as well? Ragarding table 2: what's the reason for using p{\dimexpr 0.65\linewidth-2\tabcolsep} here? You may want to replace it with an l or c type column to get closer to the expected output.
    – leandriis
    Commented Mar 28, 2022 at 6:24
  • 1
    Please also make sure to provide a minimal working example (MWE) instead of code fragments. How to make a table fit into the available space depends on how much space there is, which is in turn influenced by the documentclass, the font size and packages such as geoemetry. Parameters that you currently did not share.
    – leandriis
    Commented Mar 28, 2022 at 6:27
  • 1
    Since it it unknown what's inside of packages.tex, unfortunately not really. Please also add this information directly into your question using the "edit" button. Code in the comments get overlooked too easily.
    – leandriis
    Commented Mar 28, 2022 at 6:40

2 Answers 2

6

Edit:* Now both tables:

enter image description here

enter image description here

With use of tabularray package with libraries booktabs and siunitx:

\documentclass[12pt, a4paper]{report}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage{newtxtext} 
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
  \ExplSyntaxOn
\NewChildSelector{eachtwo}
  {
    \int_step_inline:nnnn {2}{2}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

\begin{document}
\begin{table}[ht]
   \caption{Summary of gene inputs and pathway outputs for pathway analysis of the isografts}
\begin{tblr}{colsep  = 3pt,
             colspec = {@{} l
                        X[0.8, c, si={table-format=4.0}] 
                        l
                        X[1.2, c, si={table-format=2.0}]
                        @{}},
            rowsep = 0.5pt,
            row{1} = {font=\small\bfseries, m},
            row{eachtwo} = {abovesep=1ex},
            }
   \toprule
{Timepoint\\ comparison}
    & {{{Total number\\ of input genes $(P<0.01)$}}} 
        & {{{Pathway\\ outputs}}} 
            & {{{No. of statistically significant enriched pathways $(P<0.05)$}}}\\
   \midrule
T0-T1g downregulated 
    & 2308  & Immunological & 0             \\
    &       & Inflammatory  & 2             \\
T0-T1g upregulated 
    & 2187  & Immunological & 14            \\
    &       & Inflammatory  & 28            \\
T1g-T7g downregulated 
    & 2034  & Immunological & 1             \\
    &       & Inflammatory  & 15            \\
T1g-T7g upregulated 
    & 1897  & Immunological & 1             \\
    &       & Inflammatory  & 2             \\
T7g-T30g downregulated 
    & 1360  & Immunological & 3             \\
    &       & Inflammatory  & 2             \\
T7g-T30g upregulated 
    & 751   & Immunological & 4             \\
    &       & Inflammatory  & 8             \\
   \bottomrule
   \end{tblr}
\end{table}


\begin{table}[ht]
   \caption{Serum markers in the allograft recipients with no significant difference in concentrations between timepoints}
\begin{tblr}{colspec = {c
                        X[l]
                        Q[c, si={table-format=4.1}]
                        },
            rowsep = 0.5pt,
            row{1} = {font=\small\bfseries, c, m},
            row{eachtwo} = {abovesep=1ex},
            }
   \toprule
{Serum\\ marker}
    & \SetCell[c=2]{c}  {Limit of Detection (LOD)\\ (pg/mL)}
                            &           \\
   \midrule
1.  &   AR (amphiregulin)   & 13.6      \\
2.  &   B7-1 (CD80)         & 35.3      \\
3.  &   BAFF-R (B cell activating factor receptor)
                            & 7.7       \\
4.  &   BTC (betacellulin)  & 5.7       \\
5.  &   C5a (complement C5 alpha chain)
                            & 1.7       \\
6.  &   CCL6    (C-C motif chemokine 6)
                            & 23.2      \\
7.  &   CD6 (T cell differentiation antigen 6)
                            & 2.5       \\
8.  &   CX3CL1 (Fractalkine)& 2016.3    \\
32. &   Marapsin            & 77.7      \\
   \bottomrule
   \end{tblr}
\end{table}
\end{document}
1

In the first table, you need to allow automatic linebreaking in columns 2 thru 4. For both tables, I suggest you employ tabularx rather than tabular environments. I don't think it's necessary to bold-face the contents of the header cells. I would align the numeric data on their explicit or implicit decimal markers. Automatic row numbering in table 2 might also be desirable.

enter image description here

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabularx} % for 'tabularx' env. and 'X' col. type
\usepackage{ragged2e} % for '\RaggedRight' and '\Centering' environment
\newcolumntype{L}{>{\RaggedRight}X} % raggedright version of 'X' col. type
\newcolumntype{C}{>{\Centering}X}   % centered version of 'X' col. type

\newcommand\mC[1]{\multicolumn{1}{C@{}}{#1}} % handy shortcut macro

\usepackage[per-mode=symbol]{siunitx}% for 'S' col. type and '\unit' macro

%% enable automatic row numbering in tables:
\newcounter{tblrow}[table]
\newcolumntype{t}{>{\refstepcounter{tblrow}\thetblrow.}r}
\begin{document}

\begin{table}[ht]
\setlength\tabcolsep{3pt} % default: 6pt
\caption{Summary of gene inputs and pathway outputs 
 for pathway analysis of the isografts}
\begin{tabularx}{\textwidth}{@{} l S[table-format=4.0] C S[table-format=4.1] @{}}
\toprule
Timepoint comparison & 
\mC{Total number of input genes ($P < 0.01$)} & 
Pathway outputs & 
\mC{Number of stat.\ sign.\ enriched pathways ($P < 0.05$)} \\ 
\midrule
T0-T1g downregulated & 2308 & Immunological & 0\\
& & Inflammatory & 2 \\
T0-T1g upregulated & 2187 & Immunological & 14 \\
& & Inflammatory & 28 \\
\addlinespace
T1g-T7g downregulated & 2034 & Immunological & 1\\
& & Inflammatory & 15 \\
T1g-T7g upregulated & 1897 & Immunological & 1\\
& & Inflammatory & 2 \\
\addlinespace
T7g-T30g downregulated & 1360 & Immunological & 3\\
& & Inflammatory & 2 \\
T7g-T30g upregulated & 751 & Immunological & 4\\
& & Inflammatory & 8 \\   %%\hdashline
\bottomrule[\heavyrulewidth] 
\end{tabularx}

\bigskip\bigskip
\caption{Serum markers in the allograft recipients with no 
  significant difference in concentrations between timepoints}
\begin{tabularx}{\textwidth}{@{} t L S[table-format=4.1] @{}}
\toprule
% '\multicolumn{1}{@{}l}{}' serves to suppress display of row counter
\multicolumn{1}{@{}l}{} & Serum marker & {Limit of Detection (LOD)} \\
\multicolumn{1}{@{}l}{} && {(\unit{\pico\gram\per\milli\liter}) } \\ 
\midrule
& AR (amphiregulin) & 13.6\\ 
& B7-1 (CD80) & 35.3\\ 
& BAFF-R (B cell activating factor receptor)  & 7.7\\ 
& BTC (betacellulin)  & 5.7\\ 
& C5a (complement C5 alpha chain) & 1.7\\ 
& CCL6    (C-C motif chemokine 6) & 23.2\\ 
& CD6 (T cell differentiation antigen 6)  & 2.5\\ 
& CX3CL1 (Fractalkine)    & 2016.3\\  
\multicolumn{1}{@{}r}{\setcounter{tblrow}{31}}& \dots \\
& Marapsin & 77.7\\ % reset value of 'tblrow' counter
\bottomrule 
\end{tabularx}
\end{table}

\end{document}

You must log in to answer this question.