这是这个问题。
我正在尝试插入不占用垂直空间但对齐方式与正常插入相同的文本。
链接问题中提供的解决方案对我来说很有效,除非我的文本不占用任何空间,并且以列表环境开头。在这种情况下,\parbox
文本顶部对齐,而不是基线对齐。
我怎样才能解决这个问题?
平均能量损失
\documentclass[twocolumn]{article}
\usepackage{ifluatex}
\ifluatex
\usepackage{lua-visual-debug}
\fi
\usepackage{enumitem}
\newdimen\savedparindent
\newdimen\savedparskip
\newcommand{\blap}[1]{%
\savedparindent\parindent
\savedparskip\parskip
\noindent
\parbox[t][0pt]{\linewidth}{%
\parindent\savedparindent
\parskip\savedparskip
#1}%
\vspace*{-\parskip}\vspace*{-\baselineskip}}
\pagestyle{empty}
\begin{document}
Some text.
\blap{This should not take up any vertical space, but should align at normal
text baseline (aligned like I want).}
\vspace{2cm}
More text.
\blap{%
\begin{itemize}[nosep]
\item This should not take up any vertical space, but should align at
normal text baseline (not aligned like I want).
\end{itemize}}
\vspace{2cm}
Yet more text.
\begin{itemize}[nosep]
\item This text takes up vertical space and aligns at normal text baseline
(aligned like I want for comparison).
\end{itemize}
\newpage
Some text.
\vspace{2cm}
More text.
\vspace{2cm}
Yet more text.
\end{document}
答案1
这是由于\parbox
和 后面的之间的交互不良造成的itemize
。例如,这个答案. 解决方法:改用minipage
。
\documentclass[twocolumn]{article}
\usepackage{enumitem}
\newdimen\savedparindent
\newdimen\savedparskip
\newcommand{\blap}[1]{%
\savedparindent\parindent
\savedparskip\parskip
\noindent
\begin{minipage}[t][0pt]{\linewidth}
\parindent\savedparindent
\parskip\savedparskip
#1%
\end{minipage}%
\vspace*{-\parskip}\vspace*{-\baselineskip}}
\pagestyle{empty}
\begin{document}
Some text.
\blap{This should not take up any vertical space, but should align at normal
text baseline (aligned like I want).}
\vspace{2cm}
More text.
\blap{%
\begin{itemize}[nosep]
\item This should not take up any vertical space, but should align at
normal text baseline (not aligned like I want).
\end{itemize}}
\vspace{2cm}
Yet more text.
\begin{itemize}[nosep]
\item This text takes up vertical space and aligns at normal text baseline
(aligned like I want for comparison).
\end{itemize}
\newpage
Some text.
\vspace{2cm}
More text.
\vspace{2cm}
Yet more text.
\end{document}
答案2
只是为了好玩,我尝试使用\smash{\vtop{...}}
for \blap
。唉,它仍然在 itemize 之前添加了一行。
看完之后此链接我发现\@minipagetrue
已经摆脱了多余的空间。
\documentclass[twocolumn]{article}
\usepackage{ifluatex}
\ifluatex
\usepackage{lua-visual-debug}
\fi
\usepackage{enumitem}
\makeatletter
\newcommand{\blap}[1]{\par\vskip-\parskip
\noindent\smash{\vtop{\@minipagetrue
#1}}%
\vspace{-\baselineskip}\allowbreak}
\makeatother
\pagestyle{empty}
\begin{document}
Some text.
\blap{%
This should not take up any vertical space, but should align at normal
text baseline (aligned like I want).}
\vspace{2cm}
More text.
\blap{%
\begin{itemize}[nosep]
\item This should not take up any vertical space, but should align at
normal text baseline (not aligned like I want).
\end{itemize}}
\vspace{2cm}
Yet more text.
\begin{itemize}[nosep]
\item This text takes up vertical space and aligns at normal text baseline
(aligned like I want for comparison).
\end{itemize}
\newpage
Some text.
\vspace{2cm}
More text.
\vspace{2cm}
Yet more text.
\end{document}