
Fiz duas perguntas anteriores sobre espaçamento vertical (primeira pergunta:Pergunta sobre sobreposição de parbox; Segunda questão:Pergunta sobre sobreposição tabular) e tenho uma última pergunta relacionada. Acontece que meu problema na Segunda Pergunta foi realmente o mesmo que a Primeira, então peço desculpas antecipadamente se novamente isso for repetitivo e estiver faltando alguma coisa (quase certamente o caso).
Estou tentando fazer com que um float com uma legenda tenha espaço vertical antes e depois, de modo que todas as linhas entrem em colapso perfeitamente. Tenho minha tentativa abaixo, onde tentei modificar \@caption
e figure
. No final das contas, só consegui fazer com que o resultado final se sobrepusesse, ainda com uma discrepância com o resultado acima.
\documentclass{article}
\usepackage{color}
\setlength{\abovecaptionskip}{0pt} % set these registers at 0pt to start
\setlength{\belowcaptionskip}{0pt}
\setlength{\intextsep}{0pt}
\begin{document}
\begingroup\centering
\textcolor{red}{Figure 1: Example}
\par\endgroup
\vskip -\baselineskip
\begin{figure}[ht] % the float should be the height of one line?
\caption{Example}
\strut Control Example (red is above, blue is below)
\end{figure}
\vskip -2\baselineskip
\begingroup\centering
\textcolor{blue}{Figure 1: Example}
\par\endgroup
\makeatletter
\long\def\@caption#1[#2]#3{% looking at the definition of caption
\par
\addcontentsline{\csname ext@#1\endcsname}{#1}%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
\begingroup
\@parboxrestore
\if@minipage
\@setminipage
\fi
\normalsize
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces
\strut #3\strut % added struts
}\par
\endgroup}
\vskip\baselineskip
\begingroup\centering
\textcolor{red}{Figure 2: Example}
\par\endgroup
\vskip -\baselineskip
\begin{figure}[ht]
\caption{Example}
\strut Now the above and below align properly.
\end{figure}
\vskip -2\baselineskip
\begingroup\centering
\textcolor{blue}{Figure 2: Example}
\par\endgroup
\newdimen\keepdepthdim % redefine the figure environment, using the solution from the First Question
\renewenvironment{figure}{\@float{figure}}{%
\par\global\keepdepthdim=\prevdepth
\end@float
\par\prevdepth=\keepdepthdim
}
\makeatother
\vskip\baselineskip
\begingroup\centering
\textcolor{red}{Figure 3: Example}
\par\endgroup
\vskip -\baselineskip
\begin{figure}[ht]
\caption{Example}
\strut Now the bottom line aligns with the caption?
\end{figure}
\vskip -2\baselineskip
\begingroup\centering
\textcolor{blue}{Figure 3: Example}
\par\endgroup
\end{document}
Responder1
Você precisa adicionar um suporte às \caption
sobreposições, já que você está alinhando partes superiores e inferiores em vez de linhas de base. Observe que \ht\strutbox+\dp\strutbox=\baselineskip
.
\documentclass{article}
\usepackage{color}
\setlength{\abovecaptionskip}{0pt} % set these registers at 0pt to start
\setlength{\belowcaptionskip}{0pt}
\setlength{\intextsep}{0pt}
\begin{document}
\begingroup\centering
\textcolor{red}{Figure 1: Example\strut}
\par\endgroup
\vskip -\baselineskip
\begin{figure}[ht] % the float should be the height of one line?
\caption{Example\strut}
%\parbox[t]{\textwidth}{\caption{Example\strut}}\llap{\rule{\textwidth}{0.4pt}}
\strut Control Example (red is above, blue is below)
\end{figure}
\vskip -2\baselineskip
\begingroup\centering
\textcolor{blue}{Figure 1: Example\strut}
\par\endgroup
\end{document}