\usepackage{booktabs} 給出錯誤

\usepackage{booktabs} 給出錯誤
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage[margin=1in]{geometry} % full-width
    \topskip        =   20pt
    \parskip        =   10pt
    \parindent      =   0 pt
    \baselineskip   =   15pt
\usepackage{pdflscape}
\usepackage{amssymb, amsfonts, amsmath}
\usepackage{bm}
\usepackage{booktabs}
\usepackage{setspace}  % line spacing
\onehalfspacing
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{rotating}  % for sidewaystable

\usepackage{threeparttable}    
\usepackage{dcolumn}    % aligning decimals
    \newcolumntype{d}[1]{D{.}{.}{#1}}

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

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

\newcommand{\sym}[1]{\rlap{#1}}
\usepackage{hyperref}
\usepackage{tabulary}

\title{Project Name}
\author{X Y Z}
\date{September 2021}

\begin{document}
\maketitle


\section*{Summary Statistics (Tables)}
\subsection*{Consent}
\begin{table}[!htbp]
    \centering
    \caption{caption}
    \label{tab:meetattend}
    \estauto{xyz.tex}{8}{c}\\
    \small{\textit{Notes:}}
\end{table}
\end{document}

我為我之前的帖子道歉。我對論壇和乳膠非常陌生,第一次發文。我的專案中有一個名為 xyz.tex 的文件,如下所示:

            &\multicolumn{8}{c}{var name}                                                               \\
            &           N&        Mean&          SD&         Min&     10th p.&      Median&     90th p.&         Max\\
\midrule
x     &         a&       b&       c&           0&           1&           1&           1&           1\\
y &         120&       0.825&       0.382&           0&           0&           1&           1&           1\\
z     &         243&       0.778&       0.417&           0&           0&           1&           1&           1\\

我在 overlead 上編譯 pdf 時遇到錯誤,但是當我刪除 \usepackage{booktabs} 時,會渲染 pdf,但表格沒有行等。我不知道為什麼會發生這種情況。任何幫助表示讚賞。

答案1

嘗試

\RequirePackage{filecontents}
    \begin{filecontents}{xyz.txt}
    & \multicolumn{8}{c}{var name} \\
    \cmidrule(l){2-9}
    & N     & Mean  & SD    & Min   & 10th p.   & Median & 90th p.  & Max   \\
    \midrule
x   & a     & b     & c     & 0     & 1         & 1      & 1        & 1     \\
y   & 120   & 0.825 & 0.382 & 0     & 0         & 1      & 1        & 1     \\
z   & 243   & 0.778 & 0.417 & 0     & 0         & 1      & 1        & 1     
    \end{filecontents}
    
\documentclass{article}
\usepackage[margin=1in]{geometry} 
\usepackage{pdflscape}
\usepackage{amsmath, amssymb}
\usepackage{bm}
\usepackage{setspace}  % line spacing
\onehalfspacing
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{rotating}  % for sidewaystable

\usepackage{booktabs}
\usepackage{dcolumn}    % aligning decimals
    \newcolumntype{d}[1]{D{.}{.}{#1}}
\usepackage{threeparttable}

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

\newcommand{\estauto}[3]{
    \begin{tabular}{l*{#2}{#3}}
    \toprule
    \estinput{#1}  \\
    \bottomrule
    \end{tabular}
                        }

\newcommand{\sym}[1]{\rlap{#1}}
\usepackage{tabulary}
\usepackage{hyperref}

\title{Project Name}
\author{X Y Z}
\date{September 2021}

\begin{document}
\maketitle

\section*{Summary Statistics (Tables)}
\subsection*{Consent}
\begin{table}[!htbp]
    \centering
    \caption{caption}
    \label{tab:meetattend}
\estauto{xyz.txt}{8}{c}     \\ % <--- added \\

    \small{\textit{Notes:}}
\end{table}
\end{document}

與您的 MWE 相比,差異在於:

  • 桌子是如何設定的
  • 如何將故事插入文檔中

編譯結果為:

在此輸入影像描述

相關內容