
명령 에 환경을 \begin{figure} ... \end{figure}
삽입 할 수 있습니까 ? \begin{table} ... \end{table}
\AtBeginDocument{}
아래 MWE를 고려하십시오.
\documentclass{article}
\usepackage{blindtext, caption}
\AtBeginDocument{
\begin{figure}[h!]\label{fig:figurelabelexample}%.........Line [1]
\centering
\rule{1.5cm}{1.5cm}
\captionof{figure}{figurecaptionexample}
\end{figure}%.............................................Line [2]
\begin{table}[h!]\label{tab:tablelabelexample}%...........Line [3]
\centering
\begin{tabular}{ l c r }
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
\captionof{table}{tablecaptionexample}
\end{table}%..............................................Line [4]
}
\begin{document}
\blindtext
\end{document}
[1-4]로 표시된 줄이 주석 처리되어 있으면 MWE 코드가 올바르게 준수됩니다. 그러나 이를 포함하면 내 컴파일러가 불평하고 오류가 발생합니다 ! LaTeX Error: Missing \begin{document}.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \begin{document}
. 이유 \begin{figure}
와 \begin{table}
충돌하는 아이디어가 있습니까 \AtBeginDocument{}
?
답변1
나는 당신이 왜 이것을 하고 싶어하는지 알 수 없습니다:-) 하지만 당신은~할 수 있었다다음을 수행하십시오.
\documentclass{article}
\usepackage{blindtext, caption}
\AtBeginDocument{\global\expandafter\let \csname @nodocument\endcsname \relax
\begin{figure}[htp!]%.........Line [1]
\centering
\rule{1.5cm}{1.5cm}
\captionof{figure}{figurecaptionexample}\label{fig:figurelabelexample}
\end{figure}%.............................................Line [2]
\begin{table}[htp!]%...........Line [3]
\centering
\begin{tabular}{ l c r }
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
\captionof{table}{tablecaptionexample}\label{tab:tablelabelexample}
\end{table}%..............................................Line [4]
}
\begin{document}
\blindtext
\end{document}
또한 라벨이 작동하도록 이동했습니다(항상 캡션 뒤에 있어야 함).
[h]
(관련이 없지만 옵션을 h
자체적으로 사용해서는 안 된다는 점을 변경했습니다 . LaTeX는 일반적으로 경고하고 다음으로 변경합니다 ht
.)