1

I would like to get an ellipsis as a single (width) character in \texttt. By default it uses three periods:

\documentclass{article}
\begin{document}
  \centering
  \begin{tabular}{rcc}
    & ellipsis & three periods\\
    plain & \textellipsis & ...\\
    teletype & \texttt{\textellipsis} & \texttt{...}
  \end{tabular}
\end{document}

compiled MWE

I assume that the current behavior means I should not consider teletype (\texttt) as monospace, but as what one would do on a typewriter?

2

You can define your own single-character-width ellipsis:

\documentclass{article}
\newcommand\monoellipsis{\hbox to.5em{\hss.\hss\hss.\hss\hss.\hss}}
\begin{document}
  \centering
  \begin{tabular}{rcc}
    & ellipsis & three periods & monoellipsis\\
    plain & \textellipsis & ... & \monoellipsis\\
    teletype & \texttt{\textellipsis} & \texttt{...} & \texttt{\monoellipsis}
  \end{tabular}
\end{document}

enter image description here

2

You can add a test for a monospaced font based on comparing the width of i and m in the current font. I use 0.5em because this is the usual width of glyphs in monospaced fonts. You might want to be on the safe side and use

\fontcharwd\font`x

instead of 0.5em and 0.33333\fontcharwd\font`x instead of 0.16667em.

\documentclass{article}

\let\kerneltextellipsis\textellipsis
\newcommand{\textmonoellipsis}{%
  \makebox[0.5em]{%
    \makebox[0.16667em]{.}\hfil
    \makebox[0.16667em]{.}\hfil
    \makebox[0.16667em]{.}%
  }%
}
\DeclareRobustCommand\textellipsis{%
  \ifdim\fontcharwd\font`i=\fontcharwd\font`m
    % i and m have equal width: monospaced font
    \textmonoellipsis
  \else
    \kerneltextellipsis
  \fi
}

\begin{document}

Normal text\dots

\texttt{Mono text\dots xyz}

\texttt{Mono textXxyz}

\end{document}

enter image description here

  • Is \dots the same as \textellipsis in text mode? – equaeghe Apr 15 '18 at 21:00
  • 1
    @equaeghe Yes: \dots actually does \ifmmode\mathellipsis\else\textellipsis\fi – egreg Apr 15 '18 at 21:03

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.