Skip to content

Instantly share code, notes, and snippets.

@malloc47
Last active February 24, 2021 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malloc47/5298181 to your computer and use it in GitHub Desktop.
Save malloc47/5298181 to your computer and use it in GitHub Desktop.
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