6

The following code does what I want, except the V acts like the p option, but I want the m option.

\documentclass[12pt]{memoir}
\usepackage{varwidth}
\begin{document}
\begin{tabular}{lV{2in}}\hline
Cat & Animal\newline Cute\newline Very furry\newline Spotted\\
\end{tabular}
\end{document}

If I use m I have to manually figure out the length of the longest item in the second column, but the word "Cat" is vertically centered like I want it.

\documentclass[12pt]{memoir}
\usepackage{varwidth}
\begin{document}
\begin{tabular}{lm{2in}}\hline
Cat & Animal\newline Cute\newline Very furry\newline Spotted\\
\end{tabular}
\end{document}

Here's what they look like:

Both examples, left is <code>m</code> right is <code>V</code>

I only found the V option via an Internet search; the varwidth manual is surprising sparse.

How do I get a table option that combines array's m and varwidth's V? (I'm actually using memoir's implementation of array if that matters.

2 Answers 2

5

I didn't know that varwidth defines the V column type. Now I know! ;-).

Its definition is

\newcolumntype{V}[1]{%
  >{\begin{varwidth}[t]{#1}\narrowragged\let\\\tabularnewline}%
  l%
  <{\@finalstrut\@arstrutbox\end{varwidth}}}

so you should get what you want by

\documentclass[12pt]{memoir}
\usepackage{varwidth}

\makeatletter
\newcolumntype{M}[1]{%
  >{\begin{varwidth}{#1}\narrowragged\let\\\tabularnewline\strut}%
  l%
  <{\@finalstrut\@arstrutbox\end{varwidth}}}
\makeatother

\begin{document}
\begin{tabular}{lM{2in}}\hline
Cat & Animal\newline Cute\newline Very furry\newline Spotted\\
\end{tabular}
\end{document}

Notice that memoir loads array (actually it has code to that effect); with other classes it will be necessary to add

\usepackage{array}

enter image description here

2
  • Yay! This works, though I was getting some really weird stuff until I realized I hadn't copied the \makeatletter part!
    – bombcar
    Mar 11, 2014 at 21:16
  • @bombcar That's implicit in .sty files, so it wasn't there to begin with.
    – egreg
    Mar 11, 2014 at 21:17
1

I'm not sure I fully understand your question, but does this answer give you the desired output? If so, I guess the question is then whether the syntax works for you.

\documentclass[12pt]{memoir}
\usepackage{stackengine}
\setstackEOL{\newline}
\setstackgap{L}{13pt}
\begin{document}
\begin{tabular}{ll}\hline
Cat & \Centerstack[l]{Animal\newline Cute\newline Very furry\newline Spotted}\\
\end{tabular}
\end{document}

enter image description here

2

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.