
Я уже задавал два предыдущих вопроса о вертикальном интервале (первый вопрос:Вопрос о перекрывающемся парбоксе; Второй вопрос:Вопрос о перекрывающихся табличных данных), и у меня есть последний связанный вопрос. Как оказалось, моя проблема во Втором вопросе была на самом деле такой же, как и в Первом, так что заранее извиняюсь, если снова повторяюсь и я просто что-то упускаю (почти наверняка так и есть).
Я пытаюсь получить плавающий элемент с подписью, чтобы иметь вертикальное пространство до и после, так что все строки идеально схлопываются. Ниже я привожу свою попытку, где я пытался изменить \@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}