2

This is a follow up to this question.

I'm trying to insert text that takes up no vertical space but aligns the same as if it was inserted normally.

The solution provided in the linked question works well for me, except if my text to take up no space begins with a list environment. In this case, the \parbox aligns at the top of the text, rather than the baseline.

How can I fix this?

MWE

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

enter image description here

David Purton
  • 25,884

2 Answers2

2

This is due to bad interaction between \parbox and the immediate following itemize. See, for instance, this answer. Solution: Use minipage instead.

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

minipage

Ruixi Zhang
  • 9,553
0

Just for fun, I experimented with using \smash{\vtop{...}} for \blap. Alas, it still added an extra line before itemize.

After reading this link I found \@minipagetrue got rid of the extra space.

\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}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120