如何从顶部排列图形/表格

如何从顶部排列图形/表格

如何从顶部开始排列图形/表格并使其彼此靠近。

以下是测试代码:

\documentclass[12pt]{article}

\begin{document}

\begin{figure}
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{figure}

\begin{table}
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{table}

\begin{figure}
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{figure}

\end{document}

现在我得到:

在此处输入图片描述

我想:

在此处输入图片描述

答案1

这是一个可能的解决方案。为具有标题功能的图形和表格定义一个新环境。

\makeatletter
\newenvironment{figurehere}  % other name for table, say tablehere
{\def\@captype{figure}}      % for table, replace figure for table
{}
\makeatother

在此处输入图片描述

代码

\documentclass[12pt]{article}
\makeatletter
\newenvironment{figurehere}
{\def\@captype{figure}}
{}

\newenvironment{tablehere}
{\def\@captype{table}}
{}
\makeatother

\begin{document}

\begin{figurehere}
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{figurehere}

\begin{tablehere}
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{tablehere}

\begin{figurehere}
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{figurehere}

\end{document}

答案2

如果我理解您的设置正确的话,这三个浮动元素将放置在仅浮动元素的页面上。如果是这种情况,您可以继续 (i) 重新定义长度参数\@fptop和 (ii) 使用浮动元素的[t]位置[h]说明符。

在下面的例子中,细线是通过包showframe的选项绘制的geometry

在此处输入图片描述

\documentclass[12pt]{article}
\makeatletter % use this instruction b/c "\@fptop"  contains a "special" character
\setlength{\@fptop}{0pt} % in floats-only pages, don't insert `vfill` at the top
\makeatother
\usepackage[showframe]{geometry} % just for this example
\begin{document}

\begin{figure}[t]
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{figure}

\begin{table}[h]
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{table}

\begin{figure}[h]
\caption{A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!A very long caption!}
\end{figure}
\end{document} 

相关内容