# Combining threeparttable with cross references - LyX

I was wondering if there was a known issue with combining threeparttable with cross references inside a float. I have my labels inside the table captions, and this works just fine unless threeparttable is called, in which case the references are ?? once it's compiled. Any suggestions would be appreciated.

ETA: Thank you scottkosty, of course I should add more detail. Here is a screenshot of one of the tables in LyX, with the threeparttable command:

And here is the exported tex for that table, including the preamble:

%% LyX 2.0.6 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[12pt,british,american,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{color}
\usepackage{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{setspace}
\onehalfspacing
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
{hyperref}
\usepackage{breakurl}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
%% A simple dot to overcome graphicx limitations
\newcommand{\lyxdot}{.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.

\usepackage{amsfonts}
\usepackage{chicago}
\usepackage{pdflscape}
\usepackage{appendix}
\usepackage{hyperref}
\usepackage[letterpaper,top=1in,right=1in,left=1in,bottom=1in]{geometry}
\usepackage[bottom]{footmisc}
%\usepackage{fancyhdr}
\usepackage{bibentry}
\usepackage{threeparttable}
\usepackage{dcolumn}
\usepackage{booktabs}

\setcounter{MaxMatrixCols}{10}

\newtheorem{theorem}{Theorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Conclusion}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{lemma}{Lemma}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}{Proposition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{solution}[theorem]{Solution}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}

% For centered entries:
% Allow line breaks with \\ in specialcells
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}
}

% For left-aligned entries:
%% Allow line breaks with \\ in specialcells
%\newcommand{\specialcell}[2][c]{%
%\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}% missing % in original
%                       %%%
%}

% *****************************************************************
% siunitx
% *****************************************************************
\newcommand{\sym}[1]{\rlap{#1}} % Thanks to Joseph Wright & David Carlisle

\usepackage{siunitx}
\sisetup{
detect-mode,
group-digits            = false,
input-symbols           = ( ) [ ] - +,
tight-spacing       = true,
table-align-text-post   = false,
input-signs             = ,
}

% Packages for tables
\usepackage{booktabs}% Pretty tables
\usepackage{threeparttablex}% For Notes below table

% Character substitution that prints brackets and the minus symbol in text mode. Thanks to David Carlisle
\def\yyy{%
\bgroup\uccode\~\expandafter\string-%
\uppercase{\egroup\edef~{\noexpand\text{\llap{\textendash}\relax}}}%
\mathcode\expandafter\string-"8000 }

\def\xxxl#1{%
\bgroup\uccode\~\expandafter\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\llap{\string#1}}}}%
\mathcode\expandafter\string#1"8000 }

\def\xxxr#1{%
\bgroup\uccode\~\expandafter\string#1%
\uppercase{\egroup\edef~{\noexpand\text{\noexpand\rlap{\string#1}}}}%
\mathcode\expandafter\string#1"8000 }

\def\textsymbols{\xxxl[\xxxr]\xxxl(\xxxr)\yyy}

% *****************************************************************
% Estout related things
% *****************************************************************
\let\estinput=\input % define a new input command so that we can still flatten the document

\newcommand{\estwide}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular*}
{\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\end{tabular*}
}
}

\newcommand{\estauto}[3]{
\vspace{.75ex}{
\textsymbols% Note the added command here
\begin{tabular}{l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\end{tabular}
}
}

% *****************************************************************
% Custom subcaptions
% *****************************************************************
% Note/Source/Text after Tables
% The new approach using threeparttables to generate notes that are the exact width of the table.
\newcommand{\Figtext}[1]{%
\begin{tablenotes}[para,flushleft]
\hspace{6pt}
\hangindent=1.75em
#1
\end{tablenotes}
}
\newcommand{\Fignote}[1]{\Figtext{\emph{Note:~}~#1}}
\newcommand{\Figsource}[1]{\Figtext{\emph{Source:~}~#1}}
\newcommand{\Starnote}{\Figtext{* p < 0.1, ** p < 0.05, *** p < 0.01. Standard errors in parentheses.}}% Add significance note with \starnote

\usepackage{changepage}

\usepackage{bbm}
\usepackage{bm}

\makeatother

\begin{document}
\begin{onehalfspace}

\begin{table}[!t]
\centering
\begin{threeparttable}

\caption{\label{tab:indices_plain}Treatment effects on index variables}

{\scriptsize\include{../Output/indices_plain}}

\selectlanguage{british}%
\begin{tablenotes}[flushleft] \scriptsize \item \emph{Notes:}
OLS estimates of treatment and spillover effects. Outcome variables are listed on the left. Column (1) reports the mean of the control group for a given outcome variable. Column (2) reports the treatment effect across villages, i.e. comparing treatment households to pure control households. Column (3) reports the treatment effect within villages, i.e. comparing treatment housholds to control households in treatment villages (spillover households). Column (4) reports the spillover effect, i.e. the treatment effect on spillover households compared to pure control households. The unit of observation is the household for all outcome variables, except the psychological variables index, where it is the individual. The sample includes all households and individuals, except for the intrahousehold index, where it is restricted to co-habitating couples, and for the education index, where it is restricted to households with school-age children. For each outcome variable, we report the coefficient of interest, its standard error in parentheses, and the bootstrapped FWER $p$-value in brackets. Standard errors are clustered at the village level in columns (2) and (4), and at the household level in column (3). * denotes significance at 10 pct., ** at 5 pct., and *** at 1 pct. level.
\end{tablenotes}
\end{threeparttable}\selectlanguage{english}%
\end{table}

\end{document}


Hopefully this helps describe the situation. I'm using LyX version 2.0.6, with the MacTeX package 2013. Thank you all!

• Please provide a LyX Minimal Example and also export that to LaTeX and post that as well. Please also export one of those to PDF and post that so that we can easily see what you get (this might not be the same as what we get as ouput and can help when helping you). Also with LyX questions it's useful if you give your LyX version number, operating system, and TeX distribution (e.g. TeX Live). – scottkosty Jul 30 '13 at 3:12
• Edited with the information you suggested. Thanks for the comments. – nicholson Jul 31 '13 at 17:53
• What's in indices_plain? When I replace that line with a simple tabular, I get the caption and reference as expected. – Torbjørn T. Jul 31 '13 at 20:06
• Thanks for the suggestion. indices_plain.tex is a tabular getting output by another program, inserted into the float as a child document. It does seem to have something to do with the problem, but unfortunately I don't think copying over tabulars is an option in this case (there are ~70 of these tables, and they get updated often). – nicholson Aug 1 '13 at 20:03
• Sorry, I wasn't notified of your comment (add @username to make sure people are notified). Just realized that you use Include to add the tabular file: Don't. Include adds a \clearpage, try with Input instead. – Torbjørn T. Aug 3 '13 at 21:03

You have used \include to add the external file with the table, and this is not recommended -- \input should be used instead. See When should I use \input vs. \include? for details. Basically, \include should be used when the external file contains a longer part of a document (e.g. an entire chapter), that should start on a new page, whereas \input can be used for shorter pieces of code. \input is basically the same as writing the content directly in the LaTeX file.
Not exactly sure what happens when \include is used like that, but when I replace it with \input in your sample LaTeX file, the cross reference works fine.
Click on the box saying Include:indices_plain.tex`, and change the Include Type to Input: