1

I'm writing my thesis using the book document class. Each paragraph is indented automatically. This is fine with me for the whole thesis except in small pieces of "code" that are enclosed between \texttt. I would like to eliminate the indentation in this case but I can't. I tried with /noindent but remains a small space (shorter than the indentation but a space). Then I tried it but has no effect because the indentation remains.

\texttt{
{\setlength{\parindent}{0cm}
text 1: Follow the white rabbit!\\
text 2: Follow the tiny white rabbit!\\
}
}

How can I fix? Thanks!

  • You wanna typeset code, do it properly (using package listings or minted`). Alternatively, you want to typeset an algorithm. Several packages for algorithms available as well. – Johannes_B Oct 25 '15 at 16:17
  • Do you maybe want something like the verbatim environment? This would be better although adding \noindent before \texttt would kill the indentation. – cfr Oct 25 '15 at 16:17
  • What you are doing right now, is starting a new paragraph and setting the parindent to zero, this is to late. – Johannes_B Oct 25 '15 at 16:17
  • @Johannes_B I simply wish that these two lines are in black font as \texttt and no indentation.. What is the easiest way to do it? I used listings in another part of the thesis formatting code in a certain way which in this case would not fit... – lonely Oct 25 '15 at 16:22
  • Do it just like @cfr said in the comment above :-) – Johannes_B Oct 25 '15 at 16:24
2

Setting \parindent inside \textt is not something I'd do. Remember that an end-of-line is the same as a space:

\noindent\texttt{%
  text 1: Follow the white rabbit!\\
  text 2: Follow the tiny white rabbit!\\
}%
Some text follows.

But perhaps you want verbatim:

Some text before the typewriter type text
\begin{verbatim}
text 1: Follow the white rabbit!
text 2: Follow the tiny white rabbit!
\end{verbatim}
Some text follows.
| improve this answer | |
1

The \setlength{\parindent}{0cm} should precede the \texttt{..}, otherwise, it will not be effective. Further, you can as well use the verbatim environment (pointed out by egreg) or its \verb|..| command if it fulfills your needs.

\documentclass[12pt]{article}
\begin{document}

{\setlength{\parindent}{0cm}%
\ttfamily
text 1: Follow the white rabbit!\par
text 2: Follow the tiny white rabbit!\par
}    
\bigskip
text 1: Follow the white rabbit! \\
text 2: Follow the tiny white rabbit! 

\end{document}

enter image description here

| improve this answer | |

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.