从外部 .tex 文件导入表格时出错

从外部 .tex 文件导入表格时出错

我将下表保存到单独的 .tex 文件中。文件名为 (table.tex)

表格如下

\begin{table}[!htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{The effects of deteriorating union rights practices among trade competitors: 2SLS IV models \label{tab:baseiv}}
\small\begin{tabularx}{\textwidth}{l>{\centering}X>{\centering}X>{\centering}X>{\centering\arraybackslash}X}
\toprule
                    &\multicolumn{2}{c}{Union rights (CLR)}     &\multicolumn{2}{c}{Union rights (WorkerR)} \\\cmidrule(lr){2-3}\cmidrule(lr){4-5}
                    &\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         \\
\midrule

WTO Membership      &       0.045\sym{*}  &       0.051\sym{*}  &      -0.095         &      -0.190         \\
                    &     (0.023)         &     (0.026)         &     (0.078)         &     (0.116)         \\
Export \% of GDP    &       0.001         &       0.000         &       0.001         &       0.005         \\
                    &     (0.001)         &     (0.001)         &     (0.003)         &     (0.004)         \\
\midrule
N                   &     874.000         &     874.000         &     896.000         &     896.000         \\
Country FE          &         yes         &         yes         &         yes         &         yes         \\

Hansen J            &       0.971         &       0.960         &       0.193         &       0.937         \\
\bottomrule
\multicolumn{5}{p{\linewidth}}{\footnotesize Competition measured at the 2nd level of the SITC classification. W is min-max normalized and volume weighted. Spatially weighted exogenous instruments: number of labor INGOs and government ideology.}\\
\multicolumn{5}{p{\linewidth}}{\footnotesize Newey-West robust standard errors in parentheses - bandwidth=4. \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\).}\\
\multicolumn{5}{p{\linewidth}}{\footnotesize All regressors are lagged by one year.}\\
\end{tabularx}
\end{table}

我正在尝试将其导入到另一个 tex 文件中,我用于导入的代码是

\input{/Users/tables/table.tex}

然而由于某些原因,这会产生以下错误消息 ! Missing endcsname inserted. <to be read again> protect

有人知道是什么原因导致了这个问题吗?奇怪的是,当我将表格复制并粘贴到主 .tex 文件中时,它起作用了。因此,这不可能是表格故障。而是导入过程失败。

这是主要的 tex 文件。也许某些标题有问题?

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames*,x11names*}{xcolor}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={title},
  pdfauthor={name},
  colorlinks=true,
  linkcolor=blue,
  filecolor=Maroon,
  citecolor=Blue,
  urlcolor=Blue,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{dcolumn}
\usepackage{amsmath}
\usepackage[fontsize=11pt]{scrextend}
\usepackage{indentfirst}
\usepackage{dcolumn}
\usepackage{multirow}
\usepackage{rotating,booktabs}
\usepackage{caption}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{adjustbox}
\usepackage{ragged2e}
\usepackage{float}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{threeparttablex}
\usepackage{siunitx}
\usepackage{lipsum}
\usepackage{tablefootnote}

\title{title}
\author{name}
\date{\today}

\begin{document}
\maketitle

{
\hypersetup{linkcolor=}
\setcounter{tocdepth}{2}
\tableofcontents
}
\captionsetup{
  justification = centering
}

\input{/Users/tables/table.tex}

\end{document}

答案1

将表放入目录中User/tables创建的目录中在工作目录中(主文件 .tex 所在的位置)并使用 \input{./Users/tables/table.tex}

要得到

A

使用lualatexpdflatex以及完整序言进行了测试。

相关内容