Create a gist now

Instantly share code, notes, and snippets.

Example of LaTeX snippet that keeps text on a single line, but resizes it to fit the width, if it would otherwise wrap.
\documentclass{article}
\usepackage{xifthen}
\usepackage{graphicx}
 
\newcommand{\oneline}[1]{%
\newdimen{\namewidth}%
\setlength{\namewidth}{\widthof{#1}}%
\ifthenelse{\lengthtest{\namewidth < \textwidth}}%
{#1}% do nothing if shorter than text width
{\resizebox{\textwidth}{!}{#1}}% scale down
}
 
\begin{document}
 
\oneline{\Huge{The no-wrap text to scale}}
 
\oneline{\Huge{The quick brown fox jumped over the lazy dog, over and over and over and over again.}}
 
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment