3

I wish to achieve something that can be easily accomplished by simply pressing this button in Microsoft Word:

Distributed Text Alignment in MS Word

So that I could make something like this:

Sample title

What I've seen so far on this forum either spreads words instead of letters across the page, or statically define the spacing between letters using sodef from the soul package to mimic such effect instead of truly stretch the text to reach both ends.

I wonder if there is a single command in LaTeX that could achieve what that button can in Word.

0

4 Answers 4

2

Replace spaces by {} (so a double space will appear) and put a space after each letter.

Caveat Accented letters won't work. For that much more work is needed unless you use XeLaTeX or LuaLaTeX.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\widen}{mm}
 {
  \tl_set:Nx \l_tmpa_tl { #2 }
  \tl_replace_all:Nnn \l_tmpa_tl { ~ } { {} }
  \noindent
  \makebox[\textwidth][s]
   {
    \skip_set:Nn \spaceskip { 0pt plus 1fill }
    #1 \tl_map_inline:Nn \l_tmpa_tl { ##1 ~ } \unskip
   }
 }
\ExplSyntaxOff

\newcommand{\mytext}{SOMETHING BIG}

\begin{document}

\widen{\huge}{SOMETHING BIG}

\bigskip

\widen{\large}{\mytext}

\end{document}

enter image description here

Final note: the fact that something is easy with word processors and difficult with TeX is usually a clear sign that it's something rather dubious from the typographer's point of view.

1

Here is one option using LaTeX's \makebox with a stretched alignment:

enter image description here

\documentclass{article}
\usepackage[paper=a6paper]{geometry}% Just for this example
\setlength{\parindent}{0pt}% Just for this example
\begin{document}

\sffamily
\makebox[\linewidth][s]{\LARGE\bfseries S O M E T H I N G {} B I G}

\makebox[\linewidth][s]{s o m e t h i n g {} s m a l l}


\bigskip

\newlength{\somethingbig}
\settowidth{\somethingbig}{\LARGE\bfseries SOMETHING BIG}

{\LARGE\bfseries SOMETHING BIG}

\makebox[\somethingbig][s]{s o m e t h i n g {} s m a l l}

\end{document}
1
  • Ah I see your point. You split each word into letters so that what used to be spreading words across the line would now be spreading letters. Very smart! However, what I put in "something small" is a actually a macro that contains some string data collected from the user in the preamble of the document (a subtitle of some sort). If I am to go with this solution, I will have to write the subtitle as "s u b t i t l e", which is something I wish to avoid. Is there any way to work around this?
    – alxyzc
    Commented Jul 6, 2015 at 16:31
1

Here is a complete solution with lualatex using directlua:

\documentclass[]{article}

\usepackage{fontspec}
\setromanfont{Rockwell Extra Bold}

\newcommand\distributed[1]{%
  \makebox[\linewidth][s]{%
    \directlua{
      letters = {}
      for letter in string.gmatch("#1", ".") do
        if letter == " " then
          table.insert(letters, "{}")
        else
          table.insert(letters, letter)
        end
      end
      tex.sprint(table.concat(letters, " "))
    }%
  }%
}

\begin{document}
  \noindent{\Huge\bfseries\distributed{Hello World}}
  \distributed{Some more text}
\end{document}

This is the result: result

0

Adapting my answer at How to repeat over all characters in a string?. I had to modify it to not do the added \hfill prior to the first character.

As Werner points out, this approach cannot in general accept a macro as part of its argument.

\documentclass{article}
\usepackage{lipsum}
\newcommand\chariterate[1]{\chariteratehelpX#1 \relax\relax}
\def\chariteratehelpX#1#2\relax\relax{#1\chariteratehelpA#2\relax\relax}
\def\chariteratehelpA#1 #2\relax{%
  \chariteratehelpB#1\relax\relax%
  \ifx\relax#2\else\hfill\chariteratehelpA#2\relax\fi
}
\def\chariteratehelpB#1#2\relax{%
  \charop{#1}%
  \ifx\relax#2\else
    \chariteratehelpB#2\relax%
  \fi
}
\def\charop#1{\hfill#1}
\begin{document}
\sffamily
\noindent{\Huge\chariterate{SOMETHING BIG}}

\noindent{\scriptsize\chariterate{something small}}

\lipsum[1]
\end{document}

enter image description here

2
  • What about accepting a macro as an argument to \chariterate?
    – Werner
    Commented Jul 6, 2015 at 17:20
  • @Werner In general, that will not work. I should add that as a proviso. Commented Jul 6, 2015 at 17:30

You must log in to answer this question.

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