12

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?

lockstep
  • 250,273
cxxl
  • 1,183
  • 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

3 Answers3

9

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

cmhughes
  • 100,947
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

Bernard
  • 271,350
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} 
Fran
  • 80,769