endfloat를 사용하는 동안 \includegraphics 아래에 \caption을 사용하여 그림 위에 캡션을 렌더링합니다.

endfloat를 사용하는 동안 \includegraphics 아래에 \caption을 사용하여 그림 위에 캡션을 렌더링합니다.

배경: 내 TeX 파일은 R Markdown에서 생성되며 캡션은 포함된 그림 아래에 자동으로 배치됩니다. 다음은 생성된 TeX 파일의 모양에 대한 최소한의 예입니다.

\documentclass[man]{apa7}
\title{Test}

\begin{document}
\maketitle

Lorem ipsum

\begin{figure}
The figure
\caption{The caption.}
\end{figure}

\end{document}

문제: 그림 캡션을 렌더링해야 합니다.~ 위에이동하지 않고 해당 수치(APA 지침에 따라) \caption.

내가 시도한 것floatrow: 패키지 및 를 통해 코드를 변경하지 않고도 그림 위에 캡션을 렌더링할 수 있다는 것을 이해합니다 \floatsetup[figure]{style=plaintop}. 그러나 로드는 에 의해 로드되는 를 floatrow방해합니다 . 특히 그림은 더 이상 문서 끝에 배치되지 않고 제자리에 렌더링됩니다.endfloatapa7

\documentclass[man]{apa7}
\usepackage{floatrow}
\floatsetup[figure]{style=plaintop}

\title{Test}

\begin{document}
\maketitle

Lorem ipsum

\begin{figure}
The figure
\caption{The caption.}
\end{figure}

\end{document}

의 문서에 따르면 endfloatfloatrow항상 이전에 로드되어야 합니다 endfloat(즉, 이전에 로드되어야 함 apa7). 따라서 floatrowvia를 통해 로드하려고 시도했지만 \RequirePackage{}오류가 발생했습니다. 두 길이를 정의하지 않음으로써 그 중 일부를 수정할 수 있지만 이로 인해 해결할 수 없는 다음과 같은 오류가 발생합니다.

! Missing \endcsname inserted.
<to be read again> 
                   \@classoptionslist 
l.1453 \ProcessOptionsWithKV{floatrow}

재현 가능한 최소한의 예는 다음과 같습니다.

\RequirePackage{floatrow}
\let\abovecaptionskip\undefined
\let\belowcaptionskip\undefined

\documentclass{apa7}

\begin{document}

Lorem ipsum

\end{document}

오류 메시지에도 불구하고 예상한 대로 렌더링된 PDF 파일이 표시됩니다. 또한 이것은 특정하지 않습니다 apa7. article또는 문서 클래스를 사용할 때 동일한 오류가 발생합니다 book.

답변1

흥미롭게 figure도 apa7은 figure*. 어쨌든 기본 아이디어는 캡션과 그림을 별도의 저장 상자에 저장하고 순서를 바꾸는 것입니다.

\documentclass[man]{apa7}
%\documentclass{article}
%\usepackage{endfloat}
\usepackage{lipsum}% MWE only

% udbox is a \vbox version of lrbox
\makeatletter
\def\udbox#1{%
  \edef\reserved@a{%
  \endgroup
  \setbox#1\vbox{%
  \begingroup\aftergroup}%
  \def\noexpand\@currenvir{\@currenvir}%
  \def\noexpand\@currenvline{\on@line}}%
  \reserved@a
  \@endpefalse
  \color@setgroup
  \ignorespaces}
\def\endudbox{\unskip\color@endgroup}
\makeatother

\newsavebox{\mycaptionbox}
\newsavebox{\myfigurebox}

\makeatletter
\let\normalmakecaption=\@makecaption
\def\@makecaption#1#2{\def\test{figure}%
  \ifx\@captype\test \global\setbox\mycaptionbox=\vbox{\normalmakecaption{#1}{#2}}%
  \else \normalmakecaption{#1}{#2}%
  \fi}
\makeatother

\let\normalfigure=\figure
\let\endnormalfigure=\endfigure

\renewenvironment{figure}[1][tbp]{\normalfigure
  \begin{udbox}{\myfigurebox}}%
{\end{udbox}\unvbox\mycaptionbox
  \unvbox\myfigurebox\endnormalfigure}

\expandafter\let\expandafter\normalfigurestar\csname figure*\endcsname
\expandafter\let\expandafter\endnormalfigurestar\csname endfigure*\endcsname

\renewenvironment{figure*}[1][tbp]{\normalfigurestar
  \begin{udbox}{\myfigurebox}}%
{\end{udbox}\unvbox\mycaptionbox
  \unvbox\myfigurebox\endnormalfigurestar}

\title{Test}

\begin{document}
\maketitle

Lorem ipsum

\begin{figure}
\lipsum[1]
\caption{The caption.}
\end{figure}

\end{document}

답변2

패키지 는 내부에서 등 의 efloat재정의를 수행하며 일반적 으로 또는 로 정의됩니다 . 이 경우 패키지가 재정의를 수행하므로 둘 다 재정의를 너무 일찍 수행하게 됩니다 . 따라서 상황을 해결하는 방법은 패키지에 의한 재정의를 더욱 지연시키는 것입니다.figurefigure*\efloat@AtBeginDocument\efloat@AtBeginDocument\@iden\AtBeginDocumentfloatrow\AtBeginDocumentendfloat

운 좋게도 의 작성자는 재정의가 수행되어야 하는 정확한 순간을 사용자가 스스로 결정할 수 있는 옵션을 이미 염두에 두었 기 때문에 의 정의가 \efloat@AtBeginDocument완료되었습니다 . "(참고: \efloat@AtBeginDocument는 \를 사용하여 정의됩니다. 필요한 경우 문서 클래스와 패키지가 이를 미리 정의할 수 있도록 명령을 제공하세요.)" ( 코드 문서에서 인용)\providecommandefloatefloat

아래 솔루션은 자체 버전의 를 정의하여 나중에 적용할 수 \efloat@AtBeginDocument있는 매크로에 콘텐츠를 저장합니다 \efloatredefinitions. 특히 패키지 재정의가 floatrow이미 완료된 후에는 더욱 그렇습니다.

% Store the code of efloat re-definitions into \efloatredefinitions
% (This code must be defined before the efloat package is loaded.)
\makeatletter
\newcommand\efloatredefinitions{}
\newcommand\efloat@AtBeginDocument{\g@addto@macro\efloatredefinitions}
\makeatother

\documentclass[man]{apa7}

\usepackage{floatrow}
\floatsetup[figure]{style=plaintop}

% Do the efloat re-definitions after the re-definitions of floatrow were done
%\show\efloatredefinitions
\AtBeginDocument{\efloatredefinitions} % or simply \efloatredefinitions after \begin{document}

\title{Test}

\begin{document}
\maketitle

Lorem ipsum

\begin{figure}
The figure
\caption{The caption.}
\end{figure}

\end{document}

endfloat추신: 패키지가 "storeredefinitions" 또는 이와 유사한 옵션을 제공하여 자체적으로 \PassOptionsToPackage{storeredefinitions}{endfloat}정의하는 대신 사용할 수 있다면 좋을 것입니다 . 이에 \efloat@AtBeginDocument대해 작성자에게 이메일을 보낼 예정입니다 endfloat.

관련 정보