7

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 m right is V

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.

3 Answers 3

3

The environment {NiceTabular} of nicematrix (≥ 6.3 of 2021-10-18) supports the V columns of varwidth with an optional argument, between square brackets m, p or b for the vertical position. So, you have directly the expected output.

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

\begin{document}

\begin{NiceTabular}{lV[m]{2in}}\hline
Cat & Animal\newline Cute\newline Very furry\newline Spotted\\
\end{NiceTabular}

\end{document}

Output of the above code

Remark: The letter V supports also the keys r, l and c for the horizontal alignment.

6

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
    Commented Mar 11, 2014 at 21:16
  • @bombcar That's implicit in .sty files, so it wasn't there to begin with.
    – egreg
    Commented Mar 11, 2014 at 21:17
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .