# Spread letters to a given length?

I have made a fancy title page using titleformat and tikz, but I now face the following problem. The \chaptertitlename command returns \chaptername or \appendixname. I would like to spread the letters of the text returned by \chaptertitlename to a given length.

For example I would like to be able to call: \mycommand{\chaptertitlename}{3cm} in order to space the letters of \chaptertitlename on a total length of 3cm. How to do that ?

EDIT: This example illustrates a nearly working thing:

\documentclass[11pt]{article}
\usepackage{fontspec}

\begin{document}
\spreadletters{m y w o r d}{3cm}
\end{document}


How to convert myword to m y w o r d ?

EDIT 2: Can someone explain me why the first work and not the second one (and how to make it work) ?

\documentclass[11pt]{book}
\usepackage{fontspec}
\usepackage{seqsplit}
\usepackage[explicit]{titlesec}

\begin{document}
\chapter{First}
\spreadletters{myword}{10cm} \linebreak % This is working
\spreadletters{\chaptertitlename}{10cm} % This is not working
\end{document}

-
It's difficult to gauge whether this would work, but try adding \usepackage{seqsplit} to your document preamble and use \makebox[3cm][s]{\expandafter\seqsplit\expandafter{\chaptertitlename}} where you need it. –  Werner Apr 5 '14 at 7:09
Could you please add a minimum (working) example to your post? It would help the solvers a lot to actually start working on it. Otherwise, we are guessing how your document looks like. –  Malipivo Apr 5 '14 at 8:20
\renewcommand{\chaptername}{\protect\makebox[3cm][s]{C h a p t e r}} –  egreg Apr 5 '14 at 8:31
@egreg Is there a way to automatically convert Chapter to C h a p t e r ? –  Vincent Apr 5 '14 at 8:39
@Vincent What's the problem in just typing that command in the preamble? –  egreg Apr 5 '14 at 8:45

Using Paul Stanley's answer to your question Conditions for fancy chapter title, here's a way:

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\newcommand{\chaptercolor}{blue}
\usepackage{tikz}
\usepackage{xparse}

\titleformat{\chapter}[display]
{\normalfont\filcenter}
{\tikz[remember picture,overlay]
{\node[fill=\chaptercolor,%<--- Not hardcoded color
font=\sffamily\fontsize{96}{72}\bf\selectfont\color{white},anchor=north east,
minimum width=3cm,
minimum height=3.4cm]
at ([xshift=-1cm,yshift=-1cm]current page.north east)
(numb) {\thechapter};
\node[rotate=90,
anchor=south,
inner sep=0pt,
font=\Huge\sffamily]
at (numb.west) {\SPREAD\chaptertitlename};%<-- Not hardcoded "CHAPTER"
}}
{20pt}
{\Huge\bfseries\color{\chaptercolor}#1}%< Not hardcoded color
[\vskip10pt\Large\bfseries***]

\ExplSyntaxOn
{% full expand the argument
}
{% with \tl_map_inline:nn we insert \hfil between letters; a final \unskip kills the last \hfil
\makebox[3.4cm][s]{\tl_map_inline:nn { #1 } { ##1 \hfil } \unskip}
}
\ExplSyntaxOff

\begin{document}

\frontmatter

\chapter{Preface}

\lipsum

\mainmatter\renewcommand{\chaptercolor}{red}

\chapter{Chapter}

\lipsum

\appendix\renewcommand{\chaptercolor}{green!40!black!60}

\chapter{Appendix Something}

\end{document}


-

I enclose a small Lua snippet which add spaces after letters except commas, colons and semicolons. It adds space after spaces. This is a small example.

%! lualatex mal-words.tex
\documentclass[11pt]{article}
\pagestyle{empty}
%\usepackage{seqsplit} % 2. approach
\usepackage{luatextra}
\usepackage{luacode}

\begin{document}
\frenchspacing
%\spreadletters{my word}{3cm}\par% ->m y w o r d % 1. approach
%\makebox[3cm][s]{\expandafter\seqsplit\expandafter{my word}} % 2. approach

\begin{luacode*}
local malset={",", ";", ":"} -- A list of exceptions...

print() -- just an empty line
textlength=string.len(text) -- How many characters we are dealing with?

-- The core cycle...
for i=1,textlength do
if i>1 then bonus="\\enspace " else bonus="" end -- Starting adding spaces...
malletter=string.sub(text,i,i) -- Select only one character...

-- Is a character in the list of exceptions?
for _,v in pairs(malset) do
if v==malletter then bonus="" break end
end -- of for
tex.sprint(bonus..malletter) -- This is a way without adding \n as in print().
end -- of i
\end{luacode*}

\malword{My first, second and third word!}
\end{document}


-

with the package graphicx, you can use:

\resizebox{3cm}{!}{\chaptertitlename}

-
It is a geometric transformation of the box, I wouldn't classify it as a spreading letters situation. :-) –  Malipivo Apr 5 '14 at 8:44