This line


produces two leading spaces before the word 'Some' and the spaces before 'thing'.



does not produces the first two spaces (but produces the two spaces between the words).

Is there a way to force the leading spaces also when using \texttt?

  • Welcome to TeX.SX! Would you please correct the code to show precisely what you're doing? – egreg Oct 10 '11 at 14:15
  • 1
    Are you using that technique to get indented paragraphs? – N.N. Oct 10 '11 at 14:19
  • @Sid: Note that typewriter font is mono-spaced. As such, the lengths of the characters (and spaces) are different to the normal (roman) character widths. To see that both actually produce the same spaces (albeit of different lengths), see \fbox{~~Some~~thing} and \fbox{\texttt{~~Some~~thing}}. – Werner Oct 10 '11 at 14:23
  • I can't confirm this. Please provide an example. – Christian Lindig Oct 10 '11 at 14:25
  • 2
    I am unsure about what actually happens to the spaces, but putting a box around it does produce them. So \mbox{\texttt{~~Some~~thing}} should work as you expect it. Although the indentation will be larger, because, as Werner has already mentioned, the spaces are larger since texttt is monospaced. – Roelof Spijker Oct 10 '11 at 15:25

As egreg mentions, \texttt{~~Some} does produce leading spaces, so perhaps there was some other issue (such as paragraph indentation) messing up your experiment.

However, from the comments it appears that you are adding \textt just to include content that you don't want formatted and you want the leading spaces intacct. A simple way to do this is to use the verbatim environment:

enter image description here

Some thing
   Some more thing with leading spaces     and more space here

Had the same problem. \mbox{\texttt{}} worked for me.

  • 3
    Many users don't read comments. There needs to be an Answer block that answers or resolves the question. I am just stating that the comment helped me resolve the problem. – Jadh4v Oct 25 '15 at 0:00

If you want indented paragraphs, that is either covered by the babel package (it implements typographical conventions common to the language in use), or you should look for parindent (paragraph formatting in general) to tweak it.

It is usually a bad idea to do such each time. The advantage of LaTeX is precisely that you can apply document-wide formatting changes by adjusting parameters, local changes don't allow that. Yes, it is often necessary to reuse (part of) the text in a different setting, e.g. the technical report in a paper formatted to the exacting standards of a journal or in a presentation. And when that rolls around with it's normal "by yesterday" deadline, you'll be happy for all the time "wasted" on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.