![在 \caption[] 中放入 [] 可以起作用的原因](https://linux22.com/image/430454/%E5%9C%A8%20%5Ccaption%5B%5D%20%E4%B8%AD%E6%94%BE%E5%85%A5%20%5B%5D%20%E5%8F%AF%E4%BB%A5%E8%B5%B7%E4%BD%9C%E7%94%A8%E7%9A%84%E5%8E%9F%E5%9B%A0.png)
如果我们想将数组放在某个表格环境的标题中,我们不能这样做(这会导致错误)
\caption{A matrix here: $\begin{array}{lr} a & b \\ c & d \end{array}$}
相反,我们可以将数组放在某些表格环境的标题中,如下所示
\caption[]{A matrix here: $\begin{array}{lr} a & b \\ c & d \end{array}$}
其工作正常,没有错误。
问题:为什么在 \caption[] 中放入 [] 会起作用?谢谢!
答案1
如果不使用可选参数,主标题文本将移至表格列表中。这种移动很危险:文本必须写入文件,然后某些命令会中断。现在这种情况发生的频率比几年前要低,因为许多命令已经变得健壮,但这种情况仍然会发生。这通常有助于保护这样的命令。另请参阅https://tex.stackexchange.com/a/585716/2388
\documentclass{article}
\begin{document}
\listoftables
\begin{table}
\caption[opt]{main1}
\end{table}
\begin{table}
\caption{main2}
\end{table}
\end{document}