Insert `\hfill` after each character

Here's a microtype based solution. I've used \Huge, but the principle is the same:

\documentclass{article}
\usepackage{microtype}
\begin{document}
\centering
\parbox{.8\textwidth}{\Huge
\parfillskip=0pt
\hrule
\medskip
\textls[200]{THIS IS MY TITLE}

\medskip
\hrule}
\end{document}

One of the keys is to set \parfillskip to zero, so TeX won't add any space to fill the paragraph's last line. You can adjust the optional argument to \textls until the result is satisfying; I believe that no automated solution can substitute your eye.

example


Here's an option using a regular \makebox. The optional alignment specification s spreads out its contents to fit within the given box width. Here's a minimal example:

enter image description here

\documentclass{article}
\begin{document}
\centering
\rule{.5\linewidth}{1pt} \par
\makebox[.5\linewidth][c]{THIS IS MY TITLE} \par
\makebox[.5\linewidth][s]{T H I S {} I S {} M Y {} T I T L E} \par
\makebox[.5\linewidth][s]{T H I S {} {} I S {} {} M Y {} {} T I T L E} \par
\rule{.5\linewidth}{1pt}
\end{document}

Adding {} increases the space allowed for interword spaces.


I don't particularly care for the output, but the following does more or less exactly what you wanted.

\documentclass{article}
\usepackage{lipsum}

% The user-facing command
\newcommand\titleline[2][0.8\linewidth]{%
    {\Huge\parbox{#1}{\addhfills{#2}}\\}%
}

\makeatletter
\def\addhfills#1{%
    % rescan the argument with catcode 12 for spaces (so that they aren't ignored).
    \begingroup\catcode` =12\relax\xdef\tmp{\scantokens{#1\noexpand}}\endgroup%
    \expandafter\addhfills@@\tmp\addhfills@end%
}
% save catcode 12 space
\begingroup\catcode` =12\relax\gdef\otherspace{ }\endgroup
% an end marker
\def\addhfills@end{\relax}

\def\addhfills@@#1{#1\addhfills@@@}
\def\addhfills@@@#1{%
    \ifx#1\addhfills@end\else%
        \def\tmp{#1}%
        \ifx\tmp\otherspace%
            \hfill\hfill%
        \else%
            \hfill#1%
        \fi%
        \expandafter\addhfills@@@%
    \fi%
}

\begin{document}
\begin{center}
  \titleline{THIS IS}
  \titleline{MY TITLE}
\end{center}

\lipsum[1]
\end{document}

result

Tags:

Macros