關於標題/浮動間距的問題

關於標題/浮動間距的問題

我之前問過兩個關於垂直間距的問題(第一個問題:關於parbox重疊的問題;第二個問題:關於表格重疊的問題),我還有一個最後的相關問題。事實證明,我在第二個問題中的問題實際上與第一個問題相同,所以如果這又是重複的並且我只是遺漏了一些東西(幾乎肯定是這樣),請提前道歉。

我試圖讓一個帶有標題的浮動在前後都有垂直空間,以便所有行都能完美折疊。我在下面進行了嘗試,我嘗試修改\@captionfigure。最終,我只能讓底線重疊,與上面的線仍然存在差異。

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

相關內容