11

I am just starting to use LaTeX and I like it a lot.

When I am in a \subsection or \section I can use \quad as much as I wish and it works properly until I use a \newline (or any line breaking command for that matter). Until I change to the next section, \quad will no longer work. Any reason why that is and how I can fix it?

An example:

\quad abc  \quad bbc \newline \quad test \newline

The output:

    abc    bbc
test
  • Welcome to TeX.SE! it because of the indent added with \newline try with \newline \noindent – Cfun Jul 7 '16 at 19:47
  • 4
    LaTeX normally removes horizontal space that comes at the beginning or end of a line see hspace-is-not-working-after-newline-command – Nasser Jul 7 '16 at 19:51
  • 2
    \quad is an \hspace (actually \hskip). If it were \hspace*, that would have worked. – Werner Jul 7 '16 at 19:52
  • 1
    @SAM: \newline doesn’t add \indent by itself, since it does not terminate the current paragraph, but forces a line break whitout leaving horizontal mode. On the other hand, if you do say \newline\indent, the space added by \indent will not disappear at line breaks (because it is actually a box). – GuM Jul 7 '16 at 22:36
15

TeX removes spaces if they appear at the start of a line. You can insert a null object at the start of the line to prevent this.

\documentclass{article}
\begin{document}
\section{A section}
aaa  \quad\quad\quad bbb \newline
ccc  \quad\quad\quad ddd \newline
\null\quad\quad\quad eee fff
\end{document}

space

Of course, manually inserting line breaks is unusual, but this is the explanation.

| improve this answer | |
  • \hspace*{1em}, not \null – egreg Jul 7 '16 at 20:19
  • @IanThompson was wondering why adding manual line breaks is unusual. What would be a better approach? – user3501476 Jul 7 '16 at 20:25
  • @user3501476 --- It depends what you want to do. What are you using them for at the moment? – Ian Thompson Jul 7 '16 at 20:43
  • I was using the to create spacing after a table (embedded C++ code using the listings package). I also used them to create new paragraphs in a section which I suppose is incorrect. – user3501476 Jul 7 '16 at 20:47
  • @user3501476 --- Use a blank line in the code to indicate a new paragraph. There are better ways to insert space after a table, but I don't know what's best without seeing an example (you could ask a new question about this). – Ian Thompson Jul 7 '16 at 20:50
2

\quad inserts an \hskip which is absorbed at the start of a new line. If you want it to be used, use \hspace*{1em} (which is similar to a \quad).

You can update \quad to take a * as a possible argument, thereby using \hspace* rather than \hspace. The latter is gobbled after a line-break:

enter image description here

\documentclass{article}

\usepackage{xparse}
\DeclareDocumentCommand{\quad}{s}{%
  \IfBooleanTF{#1}
    {\hspace*{1em}}
    {\hspace{1em}}}

\begin{document}

\section{A section}
aaa  \quad\quad\quad bbb \newline
ccc  \quad\quad\quad ddd \newline
\quad*\quad\quad eee fff

\end{document}

You could do the same for \qquad.

| 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.