[Tex/LaTex] Embedding complex tables in a journal template

journaljournal-publishingtablestemplates

I spent an inordinate amount of time creating 2 beautiful tables for a manuscript. Paper accepted!

Turns out the journal wants either Word or LaTeX, but not a mix, and the tables must be in the main text itself, not separate.

This leaves me with two options:

  1. Convert the tables to Word
  2. Rewrite the paper in LaTeX (still doing most writing in Word).

(2) Seemed to be the logical choice, and I was making progress until I realized my tables can't simply cut and paste into the LaTeX document. There are all sorts of clashing errors that are extremely unfriendly to newbies. They are also landscape (wide) tables, which isn't helping.

I tried (1) using pandoc, but I get absolute garbage – jibberish and missing 90% of the text.

Table Text as follows:

\documentclass[a4paper, landscape]{article} 
% Make Landscape
\usepackage[a4paper,margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{dcolumn} 
% dcolumn to line up decimals
\usepackage{booktabs,caption}
\captionsetup[table]{name=Table} 
\usepackage[flushleft]{threeparttable} 
% The above two to allow that last line with the dagger as a bottom note.
\usepackage{caption}
\captionsetup{skip=0pt}
% Eliminates the space between the caption and the table itself.

\begin{document}

\begin{table}[!htbp] \centering 
 \begin{threeparttable}
  \caption{Regression models linking number of pregnancies to telomere length (models 1-4) and DNAmAge (models 5-8).} 
  \label{table2} 
\begin{tabular}{
>{\bfseries}l
D{.}{.}{3} 
D{.}{.}{3} 
D{.}{.}{3} 
D{.}{.}{3} 
D{.}{.}{3} 
D{.}{.}{3} 
D{.}{.}{3} 
D{.}{.}{3} } 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
\\[-1.8ex] & \multicolumn{4}{c}{\textbf{Telomere Length~}} & \multicolumn{4}{c}{\textbf{DNAmAge~}} \\ 
\\[-1.8ex] & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)$^{\dagger}$} & \multicolumn{1}{c}{(3)$^{\dagger}$} & \multicolumn{1}{c}{(4)$^{\dagger}$} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)$^{\dagger}$} & \multicolumn{1}{c}{(7)$^{\dagger}$} & \multicolumn{1}{c}{(8)$^{\dagger}$}\\ 
% You need the $ to 'leave' the text and get back to a command

\hline \\[-1.8ex] 

%%%%%%%%%

 Age & -0.047 & -0.029 & -0.028 & -0.029 & 0.485 & 0.667 & 0.656 & 0.645 \\ 
  & p = 0.003^{**} & p = 0.071^{+} & p = 0.073^{+} & p = 0.068^{+} & p = 0.293 & p = 0.157 & p = 0.158 & p = 0.165 \\ 
  No.Pregnancies & -0.014 & -0.013 & -0.014 & -0.016 & 0.363 & 0.326 & 0.459 & 0.510 \\ 
  & p = 0.025^{*} & p = 0.039^{*} & p = 0.031^{*} & p = 0.020^{*} & p = 0.026^{*} & p = 0.049^{*} & p = 0.007^{**} & p = 0.005^{**} \\ 
  SES &  & -0.006 & -0.006 & -0.004 &  & -0.180 & -0.214 & -0.291 \\ 
  &  & p = 0.143 & p = 0.161 & p = 0.395 &  & p = 0.146 & p = 0.081^{+} & p = 0.055^{+} \\ 
  Currently Pregnant (Y) &  &  & 0.011 & 0.011 &  &  & -1.472 & -1.460 \\ 
  &  &  & p = 0.534 & p = 0.540 &  &  & p = 0.001^{**} & p = 0.001^{**} \\ 
  No.Pregnancies x SES &  &  &  & -0.004 &  &  &  & 0.106 \\ 
  &  &  &  & p = 0.362 &  &  &  & p = 0.385 \\ 
  Intercept & 1.826 & 1.337 & 1.332 & 1.343 & 14.818 & 10.319 & 10.611 & 10.850 \\ 
  & p < 0.001^{**} & p < 0.001^{**} & p < 0.001^{**} & p < 0.001^{**} & p = 0.138 & p = 0.318 & p = 0.297 & p = 0.287 \\ 
 \hline \\[-1.8ex] 
\normalfont{Observations} & \multicolumn{1}{c}{821} & \multicolumn{1}{c}{821} & \multicolumn{1}{c}{821} & \multicolumn{1}{c}{821} & \multicolumn{1}{c}{397} & \multicolumn{1}{c}{397} & \multicolumn{1}{c}{397} & \multicolumn{1}{c}{397} \\ 
\normalfont{Adjusted R$^{2}$} & \multicolumn{1}{c}{0.015} & \multicolumn{1}{c}{0.063} & \multicolumn{1}{c}{0.062} & \multicolumn{1}{c}{0.062} & \multicolumn{1}{c}{0.011} & \multicolumn{1}{c}{0.041} & \multicolumn{1}{c}{0.067} & \multicolumn{1}{c}{0.067} \\ 

%%%%%%%%%%%%%%
\hline \\[-1.8ex]  
\end{tabular} 
    \begin{tablenotes}
      \small
      \item $^{\dagger}$Marked models include controls for top 10 principal components of genetic variation and average urbanicity-score (complete results in Supplementary Table S1).
      +p\textless{0.1};
      *p\textless0.05;
      **p\textless0.01;
      ***p\textless0.001 
    \end{tablenotes}
  \end{threeparttable}
\end{table}
\end{document}

Journal (Scientific Reports) Template here

Please help! I have been trying to transition to LaTeX (with R and RMarkdown) and convince others this is a good idea, but am seriously let down when I can't even embed a simple table into a pre-existing template!

Best Answer

I think you should aim to declutter the look of the table, say by moving the "p-value" reminders into the header column. Incidentally, don't bother showing the p-values of the intercept terms: Nobody cares whether these terms are significant or not.

Also, do provide more structure to the d columns; that'll tighten up the look of the table tremendously. I'd also remove all bold-facing: it doesn't actually help make the table more readable or understandable. Since you're loading the booktabs package anyway, you might as well (should?!) use its line-drawing macros instead of the generic-LaTeX \hline directive. And, since you're loading the threeparttable environment, why not also make use of the \tnote macro for the "dagger" markers in the second header row.

Off-topic: Is "urbanicity" a real word? Might "urbanization" work for you? In my view, the term "urbanicity" is particularly unfortunate as it contains the particles "urb[is]" and "city" -- two terms for, well, cities...

enter image description here

\documentclass[a4paper,landscape]{wlscirep} % see https://github.com/SFICSSS16-CircularEconomy/Documents/blob/master
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{dcolumn} % dcolumn to line up decimals
\newcolumntype{d}[1]{D..{#1}}

\usepackage{booktabs,caption}
\captionsetup[table]{name=Table} 
\captionsetup{skip=0pt}% no extra space below caption

\usepackage[flushleft]{threeparttable} 

\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{table}[!htbp] 
\centering 
\begin{threeparttable}
\caption{Regression models linking number of pregnancies to telomere length (models 1--4) and DNAmAge (models 5--8).} 
\label{table2} 

\begin{tabular}{@{} l *{8}{d{2.5}} @{}} % note: "d{2.5}", not "d{3}"
\toprule
& \multicolumn{4}{c}{Telomere Length} & \multicolumn{4}{c@{}}{DNAmAge} \\ 
\cmidrule(lr){2-5} \cmidrule(l){6-9}
& \mc{(1)} & \mc{(2)\tnote{$\dagger$}} & \mc{(3)\tnote{$\dagger$}} 
& \mc{(4)\tnote{$\dagger$}} & \mc{(5)} & \mc{(6)\tnote{$\dagger$}} 
& \mc{(7)\tnote{$\dagger$}} & \multicolumn{1}{c@{}}{(8)\tnote{$\dagger$}}\\ 

\midrule

Age & -0.047 & -0.029 & -0.028 & -0.029 & 0.485 & 0.667 & 0.656 & 0.645 \\ 
\quad$p$-values&0.003^{**} &0.071^{+} &0.073^{+} &0.068^{+} &0.293 &0.157 &0.158 &0.165 \\ \addlinespace
No.Pregnancies & -0.014 & -0.013 & -0.014 & -0.016 & 0.363 & 0.326 & 0.459 & 0.510 \\ 
\quad$p$-values&0.025^{*} &0.039^{*} &0.031^{*} &0.020^{*} &0.026^{*} &0.049^{*} &0.007^{**} &0.005^{**} \\ \addlinespace
SES &  & -0.006 & -0.006 & -0.004 &  & -0.180 & -0.214 & -0.291 \\ 
\quad$p$-values&  &0.143 &0.161 &0.395 &  &0.146 &0.081^{+} &0.055^{+} \\ \addlinespace
Currently Pregnant (Y) &  &  & 0.011 & 0.011 &  &  & -1.472 & -1.460 \\ 
\quad$p$-values&  &  &0.534 &0.540 &  &  &0.001^{**} &0.001^{**} \\ \addlinespace
No.Pregnancies $\times$ SES &  &  &  & -0.004 &  &  &  & 0.106 \\ 
\quad$p$-values&  &  &  &0.362 &  &  &  &0.385 \\ \addlinespace
Intercept & 1.826 & 1.337 & 1.332 & 1.343 & 14.818 & 10.319 & 10.611 & 10.850 \\ 
%% One usually doesn't show p-values for the intercept terms ...
%& p < 0.001^{**} & p < 0.001^{**} & p < 0.001^{**} & p < 0.001^{**} &0.138 &0.318 &0.297 &0.287 \\ 
\midrule

Observations & \mc{821} & \mc{821} & \mc{821} & \mc{821} & \mc{397} 
             & \mc{397} & \mc{397} & \multicolumn{1}{c@{}}{397} \\ 
Adjusted R$^{2}$ & \mc{0.015} & \mc{0.063} & \mc{0.062} & \mc{0.062} 
     & \mc{0.011} & \mc{0.041} & \mc{0.067} & \multicolumn{1}{c@{}}{0.067} \\ 
\bottomrule 
\end{tabular} 
\begin{tablenotes}

\small
\item[$\dagger$]Marked models include controls for top 10 principal components of 
genetic variation and average urbanicity score (complete results in 
Supplementary Table S1).

$^{+}\ p<0.1$; $^{*}\ p<0.05$; $^{**}\ p<0.01$; $^{***}\ p<0.001$.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}