Text Formattingparbox that adds no vertical space?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
verbatim
Posts: 4
Joined: Sun May 30, 2010 3:28 pm

parbox that adds no vertical space?

Post by verbatim »

I'm looking for a way to make a parbox that renders as a multi-line box of text, but whose height, for layout purposes, is considered to be just one line, so that following text is unaffected.

Here's a MWE that shows the issue:

Code: Select all

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmicx}

\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\State foo \Comment{ \parbox[t]{3in}{This is a very long comment, that needs to span several lines, but doesn't need to take up vertical space, as the following lines of code are short, and don't need comments in the margin}}
\State foo
\State foo
\State foo
\State foo
\State foo
\State foo
\end{algorithmic}
\end{algorithm}
\end{document}
Last edited by verbatim on Sun May 30, 2010 6:45 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

parbox that adds no vertical space?

Post by localghost »

You can use the \smash command to "hide" the height of a box and make the compiler neglect this height.

Code: Select all

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmicx}

\begin{document}
  \begin{algorithm}
    \begin{algorithmic}[1]
      \State foo
      \Comment{%
        \smash{%
          \parbox[t]{3in}{%
            This is a very long comment, that needs to span several lines, but doesn't need to take up vertical space, as the following lines of code are short, and don't need comments in the margin
          }
        }
      }
      \State foo
      \State foo
      \State foo
      \State foo
      \State foo
      \State foo
    \end{algorithmic}
  \end{algorithm}
\end{document}

Best regards and welcome to the board
Thorsten
verbatim
Posts: 4
Joined: Sun May 30, 2010 3:28 pm

Re: parbox that adds no vertical space?

Post by verbatim »

Perfect, thanks!
Post Reply