使用 VS Code 进行表引用

使用 VS Code 进行表引用

我对 LaTeX 文档还不太熟悉,在引用表格时遇到了问题。之前我在 Atom.io 编辑器中编译和构建,最近切换到了 VS Code。之前确实可以正常工作,但现在引用表格时出错了!

控制台一直说

第 2 页上的引用“tab:table1”未定义。

我不明白为什么以前这个方法有效,而现在却无效了?

它体现的???\ref价值。

以下是此问题重现的最小代码。我IEEEtran为我的文档使用了模板。

\documentclass[conference,compsoc]{IEEEtran}

\begin{document}

\section{Introduction}

See \ref{tab:table1}\.

\begin{table}[ht] {\renewcommand\arraystretch{1.25}
    \begin{tabular}{|l|l|l|l|} \hline
    \bf Task & \bf Assignee & \bf \multicolumn{1}{l}{Description} \\ \hline
    Project Manager & Alice & \multicolumn{1}{p{3.3cm}|}{\raggedright Schedule overall development plan and assign proper jobs to team members} \\ \hline
    Consumer & Bob & \multicolumn{1}{p{3.3cm}|}{\raggedright Test and try out a prototype application, gather the potential improvement} \\ \hline
    User & Chris & \multicolumn{1}{p{3.3cm}|}{\raggedright Gather basic feature requirement for this project by asking qeustioaires the eldery near the university.} \\ \hline
    Developer & Daniel & \multicolumn{1}{p{3.3cm}|}{\raggedright Prepare a development environment for this project and build up the application} \\ \hline
    \end{tabular}} \\
    \caption{Task distribution  for each participants of this project}
    \label{tab:table1}
\end{table}

\end{document}

在此处输入图片描述

答案1

您必须至少编译两次文档才能确保引用正确。您的代码在 Overleaf 上运行良好。

不过,我建议你加载包聪明人,这将帮助你获得更好的参考。我还加载了包大批

我还清理了您的代码,将弃用的命令\bf\ 更改为\bfseries并将第三列更改为 -column p。此外,您定义了四列,但只使用了三列。因此,我删除了第四列。

我还添加了示例 2,其中我使用书签得到一个更漂亮的表格,没有任何垂直线。除非这是你的出版商的要求,否则我会把标题移到表格上方,并使用包标题格式化。此外,我建议使用三部分表,以便将标题和表格在表格的右边距正确对齐(此外,三部分表正确处理表格注释)。

示例 1

在此处输入图片描述

\documentclass[conference,compsoc]{IEEEtran}
\usepackage{cleveref, array}

\begin{document}

\section{Introduction}

See \cref{tab:table1}.

\begin{table}[ht] \renewcommand\arraystretch{1.25}
    \begin{tabular}{|l|l|>{\raggedright\arraybackslash}p{3.3cm}|}
    \hline
    \bfseries Task & \bfseries Assignee & \multicolumn{1}{l|}{\bfseries Description} \\
    \hline
    Project Manager & Alice & Schedule overall development plan and assign proper jobs to team members \\
    \hline
    Consumer & Daniel & Test and try out a prototype application, gather the potential improvement \\
    \hline
    User & Bob & Gather basic feature requirement for this project by asking questionnaires the elderly near the university. \\
    \hline
    Developer & Chris & Prepare a development environment for this project and build up the application \\
    \hline
    \end{tabular} \\
    \caption{Task distribution  for each participants of this project%
    \label{tab:table1}}  %% Label inside caption
    \end{table}

\end{document}

示例 2 –书签标题三部分表 在此处输入图片描述

\documentclass[conference,compsoc]{IEEEtran}
\usepackage{cleveref, array, booktabs, threeparttable}
\usepackage[labelsep=period, font={footnotesize, sc}]{caption}


\begin{document}

\section{Introduction}

See \cref{tab:table1}.

\begin{table}[ht!] \renewcommand\arraystretch{1.25}

\begin{threeparttable}

    \caption{Task distribution  for each participants of this project%
    \label{tab:table1}}    %% Caption above tabular, label inside caption
    \begin{tabular}{@{}l l>{\raggedright\arraybackslash}p{3.3cm}@{}}
    \toprule
    \bfseries Task & \bfseries Assignee & \multicolumn{1}{l}{\bfseries Description} \\
    \midrule
    Project Manager & Alice & Schedule overall development plan and assign proper jobs to team members \\ 
    Consumer & Bob & Test and try out a prototype application, gather the potential improvement \\ 
    User & Chris & Gather basic feature requirement for this project by asking questionnaires the elderly near the university. \\ 
    Developer & Daniel & Prepare a development environment for this project and build up the application \\
    \bottomrule
    \end{tabular}
\end{threeparttable}
    \end{table}
\end{document}

相关内容