latex - LaTeX:无论源代码的主要块在哪里,是否可以将图像/表格放置在它们被引用的位置附近?
问题描述
我想知道是否可以将图像/表格放在靠近它们被引用的位置(它们对应\ref{images/tables}
的位置),而不管这些图像/表格的主要源代码块在哪里?例如,我想将下面提到的表格放在与 where\ref{table:1}
出现的同一页面中,但下面的代码在文档的最末尾,就在\end{document}
.
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c||}
\hline
Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
\hline\hline
1 & 6 & 87837 & 787 \\
2 & 7 & 78 & 5415 \\
3 & 545 & 778 & 7507 \\
4 & 545 & 18744 & 7560 \\
5 & 88 & 788 & 6344 \\ [1ex]
\hline
\end{tabular}
\caption{Table to test captions and labels}
\label{table:1}
\end{table}
解决方案
通常最好将源放置在第一次引用浮动的地方。但是,如果您想在一个地方收集源代码(例如外部文件或序言),您可以执行以下操作:
\documentclass{article}
\usepackage{duckuments}
\newcommand{\taba}{%
\begin{table}[htbp]
\centering
\begin{tabular}{||c c c c||}
\hline
Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
\hline\hline
1 & 6 & 87837 & 787 \\
2 & 7 & 78 & 5415 \\
3 & 545 & 778 & 7507 \\
4 & 545 & 18744 & 7560 \\
5 & 88 & 788 & 6344 \\ [1ex]
\hline
\end{tabular}
\caption{Table to test captions and labels}
\label{table:1}
\end{table}
}%
\begin{document}
\duckument
test \ref{table:1}\taba test
\duckument
\end{document}
(请不要h!
用作浮动说明符。如果有的话,这将导致浮动的次优放置。让 TeX 尽其所能:为浮动找到最佳位置)
推荐阅读
- twilio - 使用 C# 在 AutoPilot 中返回 Json
- python - 在 while 循环中使用 time.time() 会导致函数被调用两次
- python - np.sqrt np.sum 内存不足
- python - 我在使用交叉验证时遇到问题
- linux - 当我收到“文件系统已满”错误,但“df”显示有可用空间时,可能是什么问题?
- c++ - MS Detours - DetourAttach 失败
- swift - 在swift中将逗号添加到字符串整数
- javascript - Firebase 规则检查 newData 值是否超过一定数量
- flutter - 解析列表
在 Flutter 中使用 json_serializable 库 - google-apps-script - 根据条件设置字体颜色(Google-Sheets AppScript)