关于标题/浮动间距的问题

关于标题/浮动间距的问题

我之前已经问过两个关于垂直间距的问题(第一个问题:关于重叠 parbox 的问题;第二个问题:关于重叠表格的问题),我还有最后一个相关问题。事实证明,我在第二个问题中遇到的问题与第一个问题实际上相同,因此如果再次出现重复,并且我遗漏了某些内容(几乎可以肯定是这种情况),请提前致歉。

我试图让带有标题的浮动在前后留有垂直空间,以便所有行完美折叠。下面是我尝试修改\@caption和的尝试figure。最终,我只能让底线重叠,但仍然与上面的行存在差异。

\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}

在此处输入图片描述

答案1

您需要向 和 重叠部分添加支撑\caption,因为您要对齐顶部和底部而不是基线。请注意\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}

相关内容