17

I'm working on math. Here I want to reduce the spacing around the colon (':'). By default spaces are inserted before and after the colon. Could you please advise me as to how this could be rectified?

MWE:

\documentclass{book}
\usepackage{amsmath}
\begin{document}
$$
DE:AB = 18:6 \quad AB:12 = CE:15
$$
\end{document}
Stefan Pinnow
  • 29,535

4 Answers4

20

You're using the colon as an operation symbol, which is seldom done in professional mathematics, where the colon usually denotes a relation symbol. However, the colon is commonly found in elementary mathematics.

Here is a visual comparison:

\documentclass{book}

\usepackage{amsmath}

\begin{document}

\begin{align}
& DE:AB = 18:6                     && \text{too wide} \\
& DE{:}AB = 18{:}6                 && \text{too tight} \\
& DE{\,:\,}AB = 18{\,:\,}6         && \text{maybe better} \\
& DE\mathbin{:}AB = 18\mathbin{:}6 && \text{right, IMO} 
\end{align}

\end{document}

enter image description here

When you have decided what's best for you, add one of the following definitions (\rt is for ‘ratio’, choose a different name if you wish):

\newcommand{\rt}{{:}}         % for choice 2
\newcommand{\rt}{{\,:\,}}     % for choice 3
\newcommand{\rt}{\mathbin{:}} % for choice 4

and input your proportions as

DE \rt AB = 18 \rt 6
egreg
  • 1,121,712
11

Just put the colons in groups.

\documentclass{book}

\usepackage{amsmath}

\begin{document}

\[
DE{:}AB = 18{:}6 \quad AB{:}12 = CE{:}15
\]

\end{document}
9

You can redeclare : to be of class \mathord. If have to restore the original behaviour, use \mathrel{:}.

\documentclass{book}

\usepackage{amsmath}

\DeclareMathSymbol{:}{\mathord}{operators}{"3A}

\begin{document}

\[ DE:AB = 18:6 \quad AB:12 = CE:15 \]

\end{document}

enter image description here

Henri Menke
  • 109,596
  • 2
    I’d go for a different name, e.g., \DeclareMathSymbol{\dv}{\mathord}{operators}{"3A}. I’d also consider \DeclareMathSymbol{\dv}{\mathbin}{operators}{"3A}. – GuM May 22 '18 at 07:30
  • @GuM See updated answer. I don't think you have to wrap it in a command. After all you want the spacing around colon to be consistent throughout. But it's good to know how to go back, which I have added to my answer. – Henri Menke May 22 '18 at 07:51
  • @GuM After seeing the output, I’d go for something like \newcommand\dv{\,{:}\,} – egreg May 22 '18 at 08:11
  • @egreg: I cannot make up my mind for either of the two variants (thin space or medium space). Perhaps a matter of personal taste. Maybe \newcommand*\dv{\noscript\,{:}\noscript\,} (or a robustified version thereof)? – GuM May 22 '18 at 18:32
  • Hi Henri thanks for your suggestion it has helpful and working fine. – Rajesh Kumar May 24 '18 at 06:54
2

I propose a command that seems cleaner in my opinion, and that lets you postpone the decision (in case you want to fine tune the output in the future)

\newcommand*\ratio[1]{\cleanratio#1\relax}
\def\cleanratio#1:#2\relax{#1\mathbin{:}#2}

and then use \ratio{DE:AB} = \ratio{18:6} = \ratio{3:1}. That way if you want to change the output you can (for instance #1\,\mathord{:}\,#2, or whatever). If you prefer a cleaner syntax like \ratio DE:AB = \ratio 18:6 = \ratio 3:1 we can implement it.

Manuel
  • 27,118