25

For a book cover, I want to write the title vertically (like in Japanese, but using English text):

         T
T        I
H        T
I  I  M  L
S  S  Y  E

How do I do this without jumping through a host of \vbox and \hboxes?

user3671
  • 655

3 Answers3

23

enter image description here

\documentclass{article}



\makeatletter
\protected\def\vvv#1{\leavevmode\bgroup\vbox\bgroup\xvvv#1\relax}

\def\xvvv{\afterassignment\xxvvv\let\tmp= }

\def\xxvvv{%
\ifx\tmp\@sptoken\egroup\ \vbox\bgroup\let\next\xvvv
\else\ifx\tmp\relax\egroup\egroup\let\next\relax
\else
%\hbox{\tmp}%original
\hbox to 1.1em{\hfill\tmp\hfill}% centred
\let\next\xvvv\fi\fi
\next}

\makeatother

\begin{document}

\vvv{This is my title}

\end{document}
David Carlisle
  • 757,742
  • @user3671 note I added an extra \egroup in the code (otherwise you get a warning about an unclosed group) – David Carlisle Jul 04 '13 at 16:51
  • Is there some way of using \vvv directly in \maketitle? – user3671 Jul 04 '13 at 16:59
  • It should just work: \title{\vvv{This is my title}} \maketitle works for me, but in practice the standard title layout is not designed for this so you'd want to use titlepage not \maketitle and position it by hand. – David Carlisle Jul 04 '13 at 17:03
  • Works for regular book layout, but not for tufte-book, which I'm using. Too bad. Thanks anyways for this neat piece of coding, David. – user3671 Jul 05 '13 at 02:55
  • @DavidCarlisle: The extra \egroup is not needed, if you remove the extra \bgroup after \leavevmode. – Heiko Oberdiek Jul 19 '13 at 23:56
  • @user3671: It also works for tufte-book, if you define the macro as protected macro: \protected\def\vvv#1{...} – Heiko Oberdiek Jul 19 '13 at 23:56
  • @HeikoOberdiek thanks I added \protected (by the way you can edit my answers any time:-) I left in the bgroup-egroup as I recall having a plan for them at the time, although they are not really doing much here. – David Carlisle Jul 20 '13 at 00:05
  • @DavidCarlisle: BTW, the characters can be horizontally centered using something like \hbox to 1.1em{\hfill\tmp\hfill} instead of \hbox{\tmp}. – Heiko Oberdiek Jul 20 '13 at 00:08
  • @HeikoOberdiek yes I wished afterwards I'd done that but the OP seemed happy and life rolled on so I didn't go back and edit it, I suppose I should since you've poked a finger at me... – David Carlisle Jul 20 '13 at 00:15
  • @HeikoOberdiek done:-) – David Carlisle Jul 20 '13 at 00:18
20

Split the title at spaces, then each word at letters and build a tabular for each word. Then print all the tabulars so obtained:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xparse}
\ExplSyntaxOn

% variables
\seq_new:N \l_verttext_words_seq
\seq_new:N \l_verttext_singleword_seq
\seq_new:N \l_verttext_final_seq

% user level command
\NewDocumentCommand{\verticaltitle}{m}
 {
  {\huge\verttext_title:n { #1 }\par}
 }

% Inner function
\cs_new_protected:Npn \verttext_title:n #1
 {
  % clear the sequence holding the final result
  \seq_clear:N \l_verttext_final_seq
  % split the title at spaces
  \seq_set_split:Nnn \l_verttext_words_seq { ~ } { #1 }
  % from each word build a tabular
  \seq_map_inline:Nn \l_verttext_words_seq
   {
    % split the word into letters
    \seq_set_split:Nnn \l_verttext_singleword_seq { } { ##1 }
    % build the tabular for the single word
    \seq_put_right:Nx \l_verttext_final_seq
     {
      \exp_not:n { \begin{tabular}[b]{@{}c@{}} }
      \seq_use:Nnnn \l_verttext_singleword_seq { \\ } { \\ } { \\ } 
      \exp_not:n { \end{tabular} }
     }
   }
  % output the tabulars separated by a \qquad
  \seq_use:Nnnn \l_verttext_final_seq { \qquad } { \qquad } { \qquad }
 }

\ExplSyntaxOff

\begin{document}

\verticaltitle{THIS IS MY TITL{É}}

\end{document}

Note that special letter must be braced; not a big deal with a title. You may want to increase \arraystretch in case accented letters are used.

enter image description here

egreg
  • 1,121,712
  • Many thanks, egreg. I marked David's response correct because I tried it out first because it looked simpler. – user3671 Jul 04 '13 at 16:48
13
\documentclass{article}
\usepackage{stackengine}
\begin{document}
\Longstack{T H I S}
\Longstack{I S}
\Longstack{M Y}
\Longstack{T I T L E}
~~or~~
\Longstack{T H I S {}}
\Longstack{I S {} {} {}}
\Longstack{M Y {} {} {}}
\Longstack{T I T L E}

\end{document}

enter image description here

  • Worked like a charm. (I had to install stackengine.sty and readarray.sty). Many thanks. – user3671 Jul 05 '13 at 05:45
  • I cannot use this latex code. ! LaTeX Error: File `stackengine.sty' not found. –  Sep 26 '14 at 06:01
  • @ThoLe Presumably your TeX system is older and doesn't have this package available. – Joseph Wright Sep 26 '14 at 07:17
  • @ThoLe You can download stackengine at http://ctan.org/pkg/stackengine . It will work if you place the .sty file in your working directory. However, you should find out where your local LaTeX installation directory is on your machine, so that you can properly install it. – Steven B. Segletes Sep 26 '14 at 10:48