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}

  • 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} – Joshua González Mar 28 '22 at 05:11
  • sorry, that did not work in this case.. but thanks for your reply. –  Mar 28 '22 at 05:24
  • Why did not work? Please, be more exact. – wipet Mar 28 '22 at 05:28
  • 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 Mar 28 '22 at 05:36
  • First answer produced an error in compiling. It said overfull \hbox... –  Mar 28 '22 at 05:55
  • Thank you Bernard for your answer..bu sorry, I'm new to Latex, and not very savyy with understanding what code goes where.. is it possible for you to please show the suggested codes within my code? Thank you. –  Mar 28 '22 at 05:58
  • 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 Mar 28 '22 at 06: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 Mar 28 '22 at 06:27
  • Thank you leandriis for your comment. Would this info. be sufficient? \documentclass[12pt, a4paper]{report} \input{Packages.tex} \hypersetup{pdftitle = Thesis, pdfauthor = {First Last}, pdfstartview=FitH, pdfkeywords = essay, pdfpagemode=FullScreen, colorlinks, anchorcolor =., citecolor = blue, urlcolor=blue, filecolor=green, linkcolor=., plainpages=false} –  Mar 28 '22 at 06:37
  • 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 Mar 28 '22 at 06:40
  • 1
    Thanks for adding the list of packages you currently use. As far as I can tell, you should start by cleaning up your preamble before worrying about the output you get. threeparttable and ctable seem to be incompatible resulting in an error message upon trying to compile your code. Before trying to adjust the output to your liking, make sure the code compiles without any error messages. – leandriis Mar 28 '22 at 06:51
  • 1
    Also, booktabs and arydshln that define \toprule and \hdashline are currently missing. – leandriis Mar 28 '22 at 06:53
  • Thank you leandriis for pointing these out for me. So shall I then just cancel out threeparttable and ctable by typing % infront? I don't understand where to insert booktabs and arydshln. Do I add them on as \usepackage{booktabs} and \usepackage{arydshln}? Thank you! –  Mar 28 '22 at 06:59
  • 1
    Regarding booktabs and arydshln: yes. Adding them to the preamble ys you suggested makes the commands you tried to use available. Regarding threeparttable/ctable: What to do depends. If you use the commands of one of the packages, keep that package and comment out the other. If you don't use any commands from either package, comment out or remove both of them. – leandriis Mar 28 '22 at 07:02
  • 1
    Also note that putting "urgent" in the question is just going to annoy people... Under what circumstances may I add "urgent" or other similar phrases to my question, in order to obtain faster answers? - Meta Stack Overflow (stack overflow meta but also applies) – user202729 Mar 28 '22 at 07:12
  • 1
  • 1
    Off-topic: Are you absulutely sure that \usepackage[latin1]{inputenc} is correct and needed? Do give \usepackage[utf8]{inputenc} a try. – Mico Mar 28 '22 at 08:00
  • 1
    Micro, you are absolutely right. Removed latin1 and using utf8 now. Thank you! –  Mar 28 '22 at 10:08

2 Answers2

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 \
  9. & Marapsin & 77.7 \ \bottomrule \end{tblr}

\end{table} \end{document}

Zarko
  • 296,517
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}

Mico
  • 506,678