我對 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
並將第三列更改為p
-column。此外,您定義了四列,但只使用了三列。因此,我刪除了第四列。
我還提供了一個範例 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}
\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}