Latex threeparttable table notes width - latex

I am having problems with my threeparttable notes as they are somehow not covering the entire width of my table. Can anybody help me? Thank you already in advance!
Here is the code I use:
\documentclass[11pt, oneside]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{amssymb}
\usepackage[flushleft]{threeparttable}
\usepackage{longtable}
\usepackage{array}
\usepackage{pdflscape}
\usepackage{tabularx}
\usepackage{adjustbox}
\pagenumbering{gobble}
\usepackage{booktabs}
\begin{document}
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{table}
\scalebox{0.6}{
\begin{threeparttable}
\begin{tabularx}
\textwidth{lccccccccc}
& \textbf{Neonatal} & \textbf{Infant} & \textbf{Low} \\
& \textbf{Mortality} & \textbf{Mortality} & \textbf{Birthweight} & \textbf{Stunting} & \textbf{Underweight} &\\
\multicolumn{10}{c}{\noindent\rule{18cm}{0.4pt}}\\
\textit{Mother is between 17 and 19 yrs} & -0.00517*** & -0.00857*** & -0.00896** & -0.0487*** & -0.0315*** \\
& [0.001] & [0.002] & [0.004] & [0.005] & [0.004] \\
\multicolumn{10}{c}{\noindent\rule{18cm}{0.2pt}}\\
\textbf{N} & 752543 & 574609 & 399845 & 501520 & 512482 \\
\multicolumn{10}{c}{\noindent\rule{18cm}{0.4pt}}\\
\end{tabularx}
\begin{tablenotes}
\item Results are from the main results regressions (4). ***, ** and * denote significance at the 1\%, 5\%, and 10\% levels, respectively. Std. Errors in square brackets and are clustered at PSU level.
\end{tablenotes}
\end{threeparttable}
}
\end{table}
}
\end{document}

I know it's been years since your question, I am learning creating tables right now that's how I've found this question.
I think you confused the threeparttable package by declaring 10 colunms, while you have only 6 in reality. Why don't you try using 6 columns and then some way linebreak the headers and long cells instead?
\documentclass[11pt, oneside]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{amssymb}
\usepackage[flushleft]{threeparttable}
\usepackage{longtable}
\usepackage{array}
\usepackage{pdflscape}
\usepackage{tabularx}
\usepackage{adjustbox}
\pagenumbering{gobble}
\usepackage{booktabs}
\usepackage{makecell}
\renewcommand\theadalign{bc}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{\Gape[4pt]}
\renewcommand\cellgape{\Gape[4pt]}
\begin{document}
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{table}
\scalebox{0.8}{
\begin{threeparttable}
\begin{tabularx}
{16.5cm}{lccccc}
{} & \thead{Neonatal \\ Mortality} & \thead{Infant \\ Mortality} & \thead{Low \\ Birthweight} & \thead{Stunting} & \thead{Underweight} \\
\midrule
{\shortstack[l]{\textit{Mother is between} \\ \textit{17 and 19 yrs}}} & {\shortstack[c]{ $-0.00517$*** \\ $[0.001] $ }} & {\shortstack[c]{$ -0.00857$*** \\ $[0.002] $}} & {\shortstack[c]{$ -0.00896$** \\ $[0.004]$}} & {\shortstack[c]{$ -0.0487$*** \\ $[0.005]$}} & {\shortstack[c]{$-0.0315$*** \\ $[0.004]$}} \\
\midrule
\textbf{N} & 752543 & 574609 & 399845 & 501520 & 512482 \\
\midrule
\end{tabularx}
\begin{tablenotes}
\item Results are from the main results regressions (4). ***, ** and * denote significance at the 1\%, 5\%, and 10\% levels, respectively. Std. Errors in square brackets and are clustered at PSU level.
\end{tablenotes}
\end{threeparttable}
}
\end{table}
}

Related

Vertical and horizontal cell centering in LaTex table

I am making a LaTex table and have trouble centering text (and images) inside cells themselves. The table as a whole is centered on the page, but what I want is that text and images in every cell are centered both vertically and horizontally.
This is my code
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
\rowcolor[HTML]{C0C0C0}
\textbf{Particle} & \textbf{Orientation} & \textbf{Symbol} & \textbf{Letter} \\[4ex] \hline
& in & {\includegraphics[scale=0.8]{im/inel.jpg}} & $u$ \\[2ex] \cline{2-4}
\multirow{-2}{*}{fermion} & out & {\includegraphics[scale=0.8]{im/outel.jpg}} & $\overline{u}$ \\[2ex] \hline
& in & {\includegraphics[scale=0.8]{im/inpoz.jpg}} & $\overline{v}$ \\[2ex] \cline{2-4}
\multirow{-2}{*}{antifermion} & out & {\includegraphics[scale=0.8]{im/outpoz.jpg}} & $v$ \\[2ex] \hline
& in & {\includegraphics[scale=0.8]{im/inph.jpg}} & $\epsilon_\mu$ \\[2ex] \cline{2-4}
\multirow{-2}{*}{foton} & out & {\includegraphics[scale=0.8]{im/outph.jpg}} & $\epsilon_{\mu}^*$ \\[2ex] \hline
\end{tabular}
\end{table}
\end{document}
This is what my code gives me (also notice how some lines are obscured by the images - that is not how I wanted it):
And, this is what I want:
Any help is welcome! Thank you
You are already loading the tabularray package, just use it instead of a tabular:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\begin{table}[H]
\centering
\begin{tblr}{
cells={valign=m,halign=c},
row{1}={bg=lightgray,font=\bfseries,rowsep=8pt},
colspec={QQQQ},
hlines,
vlines
}
Particle & Orientation & Symbol & Letter\\
\SetCell[r=2]{} fermion& in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $u$ \\
& out & \includegraphics[scale=0.5,valign=c]{example-image-duck}& $\overline{u}$ \\
\SetCell[r=2]{} antifermion & in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\overline{v}$ \\
& out & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $v$ \\
\SetCell[r=2]{} photon & in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\epsilon_\mu$ \\
& out & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\epsilon_{\mu}^*$ \\
\end{tblr}
\end{table}
\end{document}

Overleaf Appendix Table Numbering

I am using overleaf to write a journal article and want to move a lot of my results table to the Appendix. So I write the following commands:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{outlines}
\usepackage{dirtytalk}
\usepackage{latexsym}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{booktabs,caption}
\usepackage{longtable}
\usepackage{appendix}
\usepackage[para,online,flushleft]{threeparttable}
\usepackage[affil-it]{authblk}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\renewcommand{\baselinestretch}{1.5}
\begin{document}
\bibliographystyle{IEEEtran}
\bibliography{bibliography.bib}
\appendix
\section{Tables}
\begin{table}[!]
\begin{scriptsize}
\centering
\caption{Reduced Form Estimates using Linear Probability Model}
\label{tab:my-table}
\begin{tabular}{#{}lcccc#{}}
\hline
\hline
& (1) & (2) & (3) & (4) \\
VARIABLES & A & B & C & D \\
\hline
&&&& \\
&&&& \\
&&&& \\
\hline
\multicolumn{5}{c}{\textit{Note:}Robust standard errors in parentheses *** p$<$0.01, ** p$<$0.05, * p$<$0.1 }
\end{tabular}
\end{scriptsize}
\end{table}
\end{document}
While the section is recognized as appendix and tables, the numbering of the tables continue from the main text. How do I go from for example: Table 12 to Table A1?
Thanks
You could use
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
to change the numbering style of the appendix tables
Please also note that scriptsize is NOT an environment, it is a macro.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{outlines}
\usepackage{dirtytalk}
\usepackage{latexsym}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{booktabs,caption}
\usepackage{longtable}
\usepackage{appendix}
\usepackage[para,online,flushleft]{threeparttable}
\usepackage[affil-it]{authblk}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\renewcommand{\baselinestretch}{1.5}
\begin{document}
\bibliographystyle{IEEEtran}
\bibliography{bibliography.bib}
\begin{table}[htbp]
%\begin{scriptsize}
\scriptsize
\centering
\caption{Reduced Form Estimates using Linear Probability Model}
\label{tab:my-table-}
\begin{tabular}{#{}lcccc#{}}
\hline
\hline
& (1) & (2) & (3) & (4) \\
VARIABLES & A & B & C & D \\
\hline
&&&& \\
&&&& \\
&&&& \\
\hline
\multicolumn{5}{c}{\textit{Note:}Robust standard errors in parentheses *** p$<$0.01, ** p$<$0.05, * p$<$0.1 }
\end{tabular}
%\end{scriptsize}
\end{table}
\appendix
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
\section{Tables}
\begin{table}[htbp]
%\begin{scriptsize}
\scriptsize
\centering
\caption{Reduced Form Estimates using Linear Probability Model}
\label{tab:my-table}
\begin{tabular}{#{}lcccc#{}}
\hline
\hline
& (1) & (2) & (3) & (4) \\
VARIABLES & A & B & C & D \\
\hline
&&&& \\
&&&& \\
&&&& \\
\hline
\multicolumn{5}{c}{\textit{Note:}Robust standard errors in parentheses *** p$<$0.01, ** p$<$0.05, * p$<$0.1 }
\end{tabular}
%\end{scriptsize}
\end{table}
\end{document}

latex: color one column

I would like to create a table like the following:
in which only one column has a color and the color is applied to alternate rows.
The basic table would be:
\documentclass{article}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{float}
\usepackage[margin=2cm,left=2.5cm,includefoot]{geometry}
\begin{document}
\begin{table}[!h]
\centering
\caption{HS Sections}
\begin{tabular}{ccc}
& node & degree \\
\hline
& 1 & 1 \\
& 2 & 2 \\
& 3 & 2 \\
& 4 & 4 \\
& 5 & 2 \\
& 6 & 2 \\
& 7 & 1 \\
\hline
\end{tabular}
\label{tab:Table}
\end{table}
\end{document}
You could either manually use \cellcolor{...} to colour the cells you want or you could cheat a bit by colouring the whole rows in alternate colours and then overpaint the cells of the first column with white:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{float}
\usepackage[margin=2cm,left=2.5cm,includefoot]{geometry}
\begin{document}
\begin{table}[!h]
\centering
\caption{HS Sections}
\rowcolors{2}{cyan!50}{white}
\begin{tabular}{>{\cellcolor{white}}cc}
node & degree \\
\hline
1 & 1 \\
2 & 2 \\
3 & 2 \\
4 & 4 \\
5 & 2 \\
6 & 2 \\
7 & 1 \\
\hline
\end{tabular}
\label{tab:Table}
\end{table}
\end{document}

Misplaced \noalign if using \ifstrequal

I get a "misplaced \noaling" error within an tabularx environment if I am using \ifstrequal.
This is working:
\documentclass{article}
\usepackage{tabularx}
\usepackage{etoolbox}
\begin{document}
\begin{tabularx}{\textwidth}{rrrrr}
I & am & a & useless & table \\
\ifstrequal{a}{a}{
I & am & a & useless & table \\
} {
I & am & a & useless & table \\
}
\end{tabularx}
\end{document}
This not:
\documentclass{article}
\usepackage{tabularx}
\usepackage{etoolbox}
\begin{document}
\begin{tabularx}{\textwidth}{rrrrr}
I & am & a & useless & table \\
\ifstrequal{a}{a}{
\hline
I & am & a & useless & table \\
\hline
} {
I & am & a & useless & table \\
}
\end{tabularx}
\end{document}
You could resort to good old \ifx:
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\newcommand{\stringa}{a}
\newcommand{\stringb}{b}
\begin{document}
\begin{tabularx}{\textwidth}{rrrrr}
I & am & a & useless & table \\
\ifx\stringa\stringa
\midrule
I & am & a & useless & table \\
\midrule
\else
I & am & a & useless & table \\
\fi
\end{tabularx}
\end{document}
(I'm using rules from the booktabs package instead of \hline because they give better spacing)

\footnote gives error in minipage environment with cta-author class

I need to use \footnote in a minipage environment, but it always gives an error
Command \itshape invalid in math mode. a\footnote{
mwe is
\documentclass{cta-author}
\begin{document}
\begin{table}
\begin{minipage}{\columnwidth}
\begin{tabular}{|c|c|}
\hline
Column 1 & Column2 \\
a\footnote{footnote example} & b\\
\hline
\end{tabular}
\end{minipage}
\end{table}
\end{document}
Latex class file is here
You can redefine the way cta-author makes the footnote mark. Instead of $^{...}$, use \textsuperscript{...}:
\documentclass{cta-author}
\makeatletter
\def\#makefnmark{\textsuperscript{\#thefnmark}}
\makeatother
\begin{document}
\begin{table}
\begin{minipage}{\columnwidth}
\begin{tabular}{|c|c|}
\hline
Column 1 & Column2 \\
a\footnote{footnote example} & b \\
\hline
\end{tabular}
\end{minipage}
\end{table}
% A possible work-around
\begin{table}
\begin{tabular}{|c|c|}
\hline
Column 1 & Column2 \\
a$^*$ & b \\
\hline
\end{tabular}
\medskip
\footnoterule
{\itshape\footnotesize $^*$footnote example}
\end{table}
\end{document}
And here is a visual of the work-around:

Resources