如何在longtables下写源描述?

如何在longtables下写源描述?

我希望能够添加下面的源信息figures(包括)。我已经使用了本文提供tableslongtables想法邮政,但它给出了以下错误longtables

! Misplaced \noalign.
\caption ->\noalign

是否有可能修复并拥有适用于这些环境的单一命令?

这是重现该现象的最小代码。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{longtable,booktabs}
\usepackage{blindtext}

\newcommand{\source}[1]{
 \vspace{1ex}\caption*{\textbf{Source:} {#1}}
}

\begin{document}

\begin{table}[h]
\caption{Test - Table}\label{t:test}
\begin{tabular}{p{0.5\textwidth} p{0.5\textwidth}}
\toprule
\blindtext & \blindtext \\
\bottomrule
\end{tabular}
\source{Test Test}
\end{table}

\newpage

\begin{longtable}{p{0.5\textwidth} p{0.5\textwidth}}
\caption{Test - Longtable} \label{lt:test} \\
\toprule
\blindtext & \blindtext \\
\midrule
\blindtext & \blindtext \\
\midrule
\blindtext & \blindtext \\
\bottomrule
\source{Test longtable 123}
\end{longtable}

\newpage

\begin{figure}[h]
 \centering
 \includegraphics[width=0.5\textwidth]{example-image-a}
 \caption{Test123.}\label{fig-img-a}
 \source{Test image.}
\end{figure}

\end{document}

答案1

环境不喜欢pluslongtable的组合,至少在它们之间没有 extra 是不喜欢的。\vspave\caption\\

解决方法:不要使用\vspave,而是让其\caption跳过,例如:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{longtable,booktabs}
\usepackage{blindtext}

\newcommand{\source}[1]{
 \captionsetup{skip=1ex,position=b}%
 \caption*{\textbf{Source:} {#1}}
}

\begin{document}

\begin{table}[h]
\caption{Test - Table}\label{t:test}
\begin{tabular}{p{0.5\textwidth} p{0.5\textwidth}}
\toprule
\blindtext & \blindtext \\
\bottomrule
\end{tabular}
\source{Test Test}
\end{table}

\newpage

\begin{longtable}{p{0.5\textwidth} p{0.5\textwidth}}
\caption{Test - Longtable} \label{lt:test} \\
\toprule
\blindtext & \blindtext \\
\midrule
\blindtext & \blindtext \\
\midrule
\blindtext & \blindtext \\
\bottomrule
\source{Test longtable 123} \\
\end{longtable}

\newpage

\begin{figure}[h]
 \centering
 \includegraphics[width=0.5\textwidth]{example-image-a}
 \caption{Test123.}\label{fig-img-a}
 \source{Test image.}
\end{figure}

\end{document}

相关内容