2

In the sample code below, I'd like to position the WIBBLE text so that each letter in the word is horizontal, and each successive letter in the word appears below the previous letter.

Also, the WIBBLE text should line up with the previous text. I.e. The W in the WIBBLE should line up with the lines containing the "The"'s in the other two columns.

Also, I'd prefer to avoid using graphical libraries like TikZ or MetaPost/MetaFun if possible. The stackengine package looked promising, but its commands don't seem to play well with a tabular format. Maybe it's possible and I didn't use the right formulation.

I found some related material in Vertical "stack" of letters, where every letter is rotated to sit on top of the letter beneath it

@egreg's \stack answer looks very promising, and also clean, simple, and self-contained, but using this the second and third columns move downwards. As I already said, I want it to line up. I see that answer is also using tabular, but I don't currently understand how.

\documentclass[12pt]{scrartcl}
\usepackage{stackengine}
\usepackage{longtable}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\stack}{O{c}m}
 {
  \begin{tabular}[#1]{@{}c@{}}
  \tl_map_function:nN { #2 } \__tom_stack:n
  \end{tabular}
 }
\cs_new_protected:Nn \__tom_stack:n { #1 \\ }
\ExplSyntaxOff

\begin{document}

\begin{longtable}{p{2cm}p{8cm}p{8cm}}
  & FOX & DOG \\
  \stack{WIBBLE}
 %\Longstack{W\\I\\B\\B\\L\\E}  
  & The quick brown fox jumped over the lazy dog

  & The quick brown dog jumped over the lazy fox \\
\end{longtable}

\end{document}
Faheem Mitha
  • 7,778
  • Use \stack[t]{WIBBLE} instead of \stack{WIBBLE}. –  Jan 16 '20 at 06:30
  • Schrödinger'scat: That works. Would you care to write an answer? A little context/explanation would also be most welcome. I've only the dimmest idea what @egreg's answer is doing. – Faheem Mitha Jan 16 '20 at 06:35

1 Answers1

1

The answer you are referring to just goes through the characters one by one and puts them in a tabular. A tabular comes with an optional alignment key. So if you say \stack[t]{WIBBLE}, this will create \begin{tabular}[t]{... instead of just \begin{tabular}{..., and top-align the tabular.

\documentclass[12pt]{scrartcl}
\usepackage{stackengine}
\usepackage{longtable}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\stack}{O{c}m}
 {
  \begin{tabular}[#1]{@{}c@{}}
  \tl_map_function:nN { #2 } \__tom_stack:n
  \end{tabular}
 }
\cs_new_protected:Nn \__tom_stack:n { #1 \\ }
\ExplSyntaxOff

\begin{document}

\begin{longtable}{p{2cm}p{8cm}p{8cm}}
  & FOX & DOG \\
  \stack[t]{WIBBLE}
 %\Longstack{W\\I\\B\\B\\L\\E}  
  & The quick brown fox jumped over the lazy dog

  & The quick brown dog jumped over the lazy fox \\
\end{longtable}

\end{document}

enter image description here

You probably also know that your tabular is too wide in its present form.

  • Thanks Schrödinger's cat. I didn't realise it was possible to nest tabulars. And yes, I guess the tabular columns are a bit wide. But I was trying to cram in as much text as possible. – Faheem Mitha Jan 16 '20 at 07:02