11

I feel this is rather a dumb question, but I could not find an answer. I'm looking for a \parbox without the width parameter, i.e. it should be determinded by its content. And the content is multiple lines. Something like:

       A
I like B , but who cares?
       C2

An \mbox or \makebox doesn't allow for line breaks, it seems and a \parbox wants a width parameter. There must be some easy solution for what I want, no?

  • Probably varwidth (from the package with the same name) is what you're looking for. Or just a tabular environment. – egreg Jun 29 '14 at 16:40
  • Thanks! The tabular in a simple macro works just as I want. :) – cxxl Jun 29 '14 at 17:55
7

How about a simple tabular?

% arara: pdflatex
\documentclass{article}
\begin{document}

I like \begin{tabular}{l}A\\B\\C2\end{tabular} but who cares?
\end{document}

screenshot

  • 1
    Maybe with @{}l!@{} instead of l? – egreg Jun 29 '14 at 18:03
  • @egreg yes, that would probably be best :) – cmhughes Jun 29 '14 at 18:08
  • @egreg Thank you for the comment; @{}l@{} is just what I needed for text to fit snugly around the tabular. – ShreevatsaR Nov 17 '16 at 3:02
5

Another simple solution with the stackengine package. The line separator is by default a blank space, but may be changed:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier, heuristica}

\usepackage{stackengine}

\begin{document}

I like \Centerstack[l]{A B C2} but who cares?

\end{document} 

enter image description here

1

What fun would have make a table or use a package for this? A funnier method:

\documentclass{article}
\begin{document}
I like \rlap{\raisebox{1em}{A}}\rlap{\raisebox{-1em}{C2}}B, but who cares?
\end{document} 

MWE

In the above example, the width C2 have no effect on the inline text, so the comma is over the number two. If this is a problem, simply do not use \rlap for the the longest row of stacked text:

I like \rlap{\raisebox{1em}{A}}\rlap{B}\raisebox{-1em}{C2}, but who cares?

If rows are multiline paragraphs, simply enclose it in a \parbox. Example:

\documentclass{article}
\usepackage{lipsum}
\begin{document}
I like \vrule{} 
\rlap{\raisebox{1em}{A}}\rlap{B}\raisebox{-1em}{\tiny\parbox[t]{6cm}{\lipsum[2]}}%
, but who cares?
\end{document} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.