
Fondo: Mi archivo TeX se genera a partir de R Markdown y los títulos se colocan automáticamente debajo de las figuras incluidas. Aquí hay un ejemplo mínimo de cómo se ve mi archivo TeX generado:
\documentclass[man]{apa7}
\title{Test}
\begin{document}
\maketitle
Lorem ipsum
\begin{figure}
The figure
\caption{The caption.}
\end{figure}
\end{document}
Problema: Es necesario renderizar los títulos de las figuras.arribala figura correspondiente (según pautas APA) sin moverse \caption
.
lo que he probado: Entiendo que los subtítulos se pueden representar encima de la figura sin cambiar el código a través del floatrow
paquete y \floatsetup[figure]{style=plaintop}
. Sin embargo, la carga floatrow
interfiere con endfloat
, que es cargado por apa7
. Específicamente, las cifras ya no se colocan al final del documento, sino que se muestran en su lugar:
\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}
Según la documentación de endfloat
, floatrow
siempre debe cargarse antes endfloat
(y, por tanto, antes de apa7
). Por lo tanto, intento cargar floatrow
vía \RequirePackage{}
pero esto produce errores. Puedo solucionar algunos de ellos definiendo dos longitudes, pero esto me deja con el siguiente error que parece que no puedo resolver:
! Missing \endcsname inserted.
<to be read again>
\@classoptionslist
l.1453 \ProcessOptionsWithKV{floatrow}
Aquí está el ejemplo mínimo reproducible:
\RequirePackage{floatrow}
\let\abovecaptionskip\undefined
\let\belowcaptionskip\undefined
\documentclass{apa7}
\begin{document}
Lorem ipsum
\end{document}
Tenga en cuenta que, a pesar del mensaje de error, aparece un archivo PDF renderizado con el aspecto esperado. Además, esto no es específico de apa7
; Recibo el mismo error cuando uso la clase de documento article
o book
.
Respuesta1
Curiosamente, apa7 se convierte figure
en figure*
. De todos modos, la idea básica es almacenar el título y la figura en cajas guardadas separadas e invertir su orden.
\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}
Respuesta2
El efloat
paquete está redefiniendo figure
, figure*
etc. dentro de \efloat@AtBeginDocument
, y generalmente \efloat@AtBeginDocument
se define como \@iden
o \AtBeginDocument
. En este caso, ambos harían las redefiniciones demasiado pronto, ya que el floatrow
paquete hace sus redefiniciones \AtBeginDocument
. Entonces, el truco para resolver su situación es retrasar endfloat
aún más las redefiniciones realizadas por el paquete.
Por suerte la definición de \efloat@AtBeginDocument
ya está hecha \providecommand
ya que el autor de efloat
ya tenía en mente darle al usuario la opción de autodeterminar el momento exacto en el que se deben hacer las redefiniciones: "(Nota: \efloat@AtBeginDocument se definirá usando \ proporcione un comando para que las clases de documentos y los paquetes puedan predefinirlo si es necesario)" (Cita tomada de la efloat
documentación del código)
La siguiente solución define su propia versión de \efloat@AtBeginDocument
, almacenando el contenido en una macro llamada \efloatredefinitions
que podría aplicarse más adelante, especialmente después de que ya se hayan realizado las redefiniciones del floatrow
paquete.
% 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}
PD: Sería bueno si el endfloat
paquete ofreciera una opción "storeredefinitions" o similar para \PassOptionsToPackage{storeredefinitions}{endfloat}
poder usarla en lugar de definirla \efloat@AtBeginDocument
por sí sola. Escribiré un correo electrónico al autor de endfloat
sobre esto...