使用此代码我遇到一个问题:
\documentclass[twocolumn,11pt,a4paper]{article}
\usepackage{sectsty}
\paragraphfont{\mdseries\itshape}
\usepackage[hyperref]{acl2019} % requires 'acl2019.sty'
%%%\usepackage{times}
\usepackage{latexsym}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{url}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[sorting=none]{biblatex}
\addbibresource{acl2019.bib}
\usepackage{newtxtext,newtxmath,booktabs}
\usepackage[labelfont=small,textfont={it,small},
justification=justified]{caption}
\usepackage{tabularx,ragged2e}
\newcolumntype{L}[1]{>{\RaggedRight\hsize=#1\hsize}X}
\newcolumntype{C}[1]{>{\Centering\hsize=#1\hsize\hspace{0pt}}X}
\newcommand\mycell[1]{\smash{%
\begin{tabular}[t]{@{}>{\RaggedRight}p{\hsize}@{}} #1 \end{tabular}}}
\usepackage{hyperref} % load this package last
\aclfinalcopy % requires 'acl2019.sty'
\begin{document}
\subsection{Data distributions}
you can see the figure \ref{fig:distribution} and figure \ref{fig:density}.
\begin{figure}[htpb]
\includegraphics[width=\linewidth]{Images/HC_Distribution.png}
\caption{}
\label{fig:distribution}
\end{figure}
\begin{figure}[!htpb]
\includegraphics[width=\linewidth]{Images/HC_Density.png}
\caption{}
\label{fig:density}
\end{figure}
The results are summed up in the following table \ref{table:1}.
\medskip\noindent\setlength\tabcolsep{3pt} % default: 6pt
\captionof{table}{$p$-values for various tests} \label{table:1}
\begin{tabularx}{\columnwidth}{@{}%
L{0.86} C{0.95}C{1.2}C{0.99}@{}} % Note: 0.86+0.95+1.2+0.99=4.0=# of X-type cols.
\toprule
\mycell{} & \multicolumn{3}{c@{}}{\textbf{Test}}\\
\cmidrule(l){2-4}
Patient Category & Shapiro-Wilk & D'Agostino's $K^2$ & Anderson-Darling\\
\midrule
HC & 0.315 & 0.104 & (0.334)\\
PD ICD & 0.694 & 0.180 & (0.256)\\
PD~No~ICD & 0.251 & 0.453 & (0.380)\\
\bottomrule
\multicolumn{4}{l}{\footnotesize \textit{t} statistics in parenthesis}\\
\multicolumn{4}{l}{\footnotesize * p<0.10, ** p<0.05, *** p<0.01}\\
\end{tabularx}
Then \dots
\end{document}
问题是 latex 先打印表格的标题,然后打印两个图,最后打印表格。所以标题和表格是分开的。问题出在附图中:
此时页面结束,然后:
答案1
将表和命令放在- 或- 环境\caption-of
中。我已将您的代码简化为 (M)WE。minipage
table
您还可以使用表环境,如下面的示例 2 所示:
此外,我建议你使用聪明人以供参考。然后您只需写“等”\cref{<label>}
而不是figure~ref{<label>}
“等”即可。此外,聪明人有许多其他格式化和连接的可能性ETC.,这将帮助您生成美观且一致的文档。更加方便。
\documentclass[twocolumn,11pt,a4paper, demo]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{newtxtext,newtxmath,booktabs,sectsty}
\usepackage[labelfont=small,textfont={it,small},justification=justified]{caption}
\usepackage{tabularx,ragged2e}
\newcolumntype{L}[1]{>{\RaggedRight\hsize=#1\hsize}X}
\newcolumntype{C}[1]{>{\Centering\hsize=#1\hsize\hspace{0pt}}X}
\newcommand\mycell[1]{\smash{%
\begin{tabular}[t]{@{}>{\RaggedRight}p{\hsize}@{}} #1 \end{tabular}}}
\usepackage{cleveref}
\begin{document}
\subsection{Data distributions}
you can see the \cref{fig:distribution} and \cref{fig:density}.
\begin{figure}[htpb]
\begin{center}
\includegraphics[width=\linewidth]{Images/HC_Distribution.png}
\caption{}
\label{fig:distribution}
\end{center}
\end{figure}
\begin{figure}[!htpb]
\includegraphics[width=\linewidth]{Images/HC_Density.png}
\begin{center}
\caption{}
\label{fig:density}
\end{center}
\end{figure}
The results are summed up in the following \cref{table:1}.
\noindent\begin{minipage}{\linewidth}
\medskip\setlength\tabcolsep{3pt} % default: 6pt
\captionof{table}{$p$-values for various tests}
\begin{tabularx}{\columnwidth}{@{}%
L{0.86} C{0.95}C{1.2}C{0.99}@{}} % Note: 0.86+0.95+1.2+0.99=4.0=# of X-type cols.
\toprule
\mycell{} & \multicolumn{3}{c@{}}{\textbf{Test}}\\
\cmidrule(l){2-4}
Patient Category & Shapiro-Wilk & D'Agostino's $K^2$ & Anderson-Darling\\
\midrule
HC & 0.315 & 0.104 & (0.334)\\
PD ICD & 0.694 & 0.180 & (0.256)\\
PD~No~ICD & 0.251 & 0.453 & (0.380)\\
\bottomrule
\multicolumn{4}{l}{\footnotesize \textit{t} statistics in parenthesis}\\
\multicolumn{4}{l}{\footnotesize * p<0.10, ** p<0.05, *** p<0.01}\\
\label{table:1}
\end{tabularx}
\end{minipage}
\end{document}
示例 2 - 使用表环境
我没有重复所有代码,只有表格环境。
\begin{table}[!hb]
\setlength\tabcolsep{3pt} % default: 6pt
\caption{$p$-values for various tests}
\begin{tabularx}{\columnwidth}{@{}%
L{0.86} C{0.95}C{1.2}C{0.99}@{}} % Note: 0.86+0.95+1.2+0.99=4.0=# of X-type cols.
\toprule
\mycell{} & \multicolumn{3}{c@{}}{\textbf{Test}}\\
\cmidrule(l){2-4}
Patient Category & Shapiro-Wilk & D'Agostino's $K^2$ & Anderson-Darling\\
\midrule
HC & 0.315 & 0.104 & (0.334)\\
PD ICD & 0.694 & 0.180 & (0.256)\\
PD~No~ICD & 0.251 & 0.453 & (0.380)\\
\bottomrule
\multicolumn{4}{l}{\footnotesize \textit{t} statistics in parenthesis}\\
\multicolumn{4}{l}{\footnotesize * p<0.10, ** p<0.05, *** p<0.01}\\
\label{table:1}
\end{tabularx}
\end{table}