How to produce given number of quad in math
\quad
sets a length of 1em
, with multiples X
of it being of length Xem
. So we can define \myquad[<num>]
with <num>
being optional (default of 1
), to produce a space of <num>em
:
\documentclass{article}
\newcommand{\myquad}[1][1]{\hspace*{#1em}\ignorespaces}
\begin{document}
x \quad x \par
x \myquad[1] x
x \quad\quad\qquad x \par
x \myquad[4] x
x \qquad\qquad\qquad\qquad\qquad x \par
x \myquad[10] x
\end{document}
We use \hspace*
to insert a space regardless of whether you're at the start, middle or end of a rule.
Here is version using a loop:
\documentclass{article}
\usepackage{pgffor}
\newcommand\Quad[1][1]{\foreach \Quaddy in {1,...,#1}{\quad}\ignorespaces}
\begin{document}
x \quad x \par
x \Quad[1] x
x \quad\quad\qquad x \par
x \Quad[4] x
x \qquad\qquad\qquad\qquad\qquad x \par
x \Quad[10] x
\end{document}
with output:
Personally, I prefer the more direct approach in Werner's answer.
You can look up how \quad
and \qquad
are defined, either in the LaTeX source or by asking LaTeX itself:
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=latex) restricted \write18 enabled. **\show\quad entering extended mode LaTeX2e <2016/02/01> Babel <3.9q> and hyphenation patterns for 81 language(s) loaded. > \quad=macro: ->\hskip 1em\relax . \show\quad ? *\show\qquad > \qquad=macro: ->\hskip 2em\relax . \show\qquad ? * ! Emergency stop. \show\qquad No pages of output. Transcript written on texput.log.
In many cases this will place you in a maze of twisty commands, all subtly different, but here it's pretty straightforward. A quad is a horizontal space of 1em (the nominal width of a capital M in the current font).
\newcommand{\myquad}[1]{\hskip #1 em\relax}
or in a more LaTeXish way
\newcommand{\myquad}[1]{\hspace{#1 em}}