# Centering a long line that spills over the margins.

I'm trying to TeX a fairly long line of text:

\exists C\forall f(f\in C\Leftrightarrow f\in\ms{F}\wedge (\forall x\forall y)((x\in\dom f\wedge y\in\dom f\Rightarrow x=y)\wedge(\forall z)(z\in\dom f\Rightarrow \op{z}{z}\in f))).


The problem is, when I build, the line spills a little bit into the right margin. I don't mind terribly much, as the whole line fits, but is it possible to center the line so that is spills equally over in the left and right margins? I don't really want to split this formula among two lines.

If it's helpful, my preamble is:

\documentclass[11pt]{article}
\input{other/packages.tex}
\input{other/theoremdef.tex}


where packages.tex is

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amscd}
\usepackage{url}
\usepackage[top=1.3in, bottom=1.3in, left=1.3in, right=1.3in]{geometry}

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{stackrel}
\usepackage{mathrsfs}
\usepackage{verbatim}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{xy}
\input xy
\xyoption{all}


And theoremdef.tex is:

\newtheorem{exercise}{\bf Exercise}
\newcommand{\dom}{\text{dom}\ }
\newcommand{\ran}{\text{ran}\ }
\newcommand{\fld}{\text{fld}\ }
\newcommand{\op}[2]{\langle #1,#2\rangle}
\newcommand{\ot}[3]{\langle #1,#2,#3\rangle}
\newcommand{\ms}[1]{\mathscr{#1}}


Thanks.

To resize long line you, possibly, may want to do that like this:

\newbox\formBox

\def\forMULA#1{%
\setbox\formBox=\hbox{#1}%
\centerline{%
\ifdim\wd\formBox>\linewidth%
\resizebox{\linewidth}{!}{#1}%
\else%
#1%
\fi}}

\forMULA{$\exists C\forall f(f\in C\Leftrightarrow f\in\ms{F}\wedge (\forall x\forall y)((x\in\dom f\wedge y\in\dom f\Rightarrow x=y)\wedge(\forall z)(z\in\dom f\Rightarrow \op{z}{z}\in f))).$}


This inserts (for testing purpose) your formula into a box and tests if this box's dimension exceeds \linewidth. If so, scales it to fit. If not, inserts unscaled.

\centerline is used to prevent \parindent (you may want to use \noindent instead --- if you don't need the content to be centered).

You also need to \usepackage{graphicx} --- to have \resizebox available.

But if you want to center long line (to fly out over margins equally) you may use the following:

\newbox\formBox
\newskip\formSkip

\def\forMULAE#1{%
\setbox\formBox=\hbox{#1}%
\centerline{%
\ifdim\wd\formBox>\linewidth%
\setlength{\formSkip}{{\wd\formBox - \linewidth}/2}%
\begingroup\leftskip=-\formSkip #1\endgroup%
\else%
#1%
\fi}}


This requires to \usepackage{calc} also.

• Thanks brownian, I just got around to putting this in, and it worked beautifully. – yunone Dec 31 '10 at 4:17

try this, if it is not too small: \resizebox{\linewidth}{!}{\$ ...formula ...}

With the adjustbox package you can simply write:

\adjustbox{center}{\exists C\forall f(f\in C\Leftrightarrow f\in\ms{F}\wedge (\forall x\forall y)((x\in\dom f\wedge y\in\dom f\Rightarrow x=y)\wedge(\forall z)(z\in\dom f\Rightarrow \op{z}{z}\in f))).}


to center it on the normal text area without rescaling.

If you want to rescale it to fit the line width use either width=\linewidth or better max width=\linewidth (which only scales it when the width is larger then the given value). These options should be before center, e.g. \adjustbox{max width=\linewidth,center}{...}.

Note that \adjustbox reads its content as box, so there can also be verbatim or other special content in it. There is also the adjustbox environment if you prefer that one.