I have been struggling with diagrams that exceed the margins of my document. Could you tell me how could I solve this problem without changing the margin sizes? I am using the XY package.
Thanks!
I have been struggling with diagrams that exceed the margins of my document. Could you tell me how could I solve this problem without changing the margin sizes? I am using the XY package.
Thanks!
Without knowing the specifics of your problem, I can only answer in generalities. But when you create something wider than the margin, you have several ways to deal with it. One is to redo the layout of the content. I would need to know the details of your problem to address the layout.
The other approach is to scale the content to fit the allowable size. This solution addresses this latter approach. The \scalebox macro of the graphicx package allows boxes to be scaled. So, to use this approach, you must stuff the wide content into a box, and then scale the box before typesetting it. The key lines are
\setbox0=\hbox{\widestuff}
\scalebox{.8}{\box0}
which takes wide content and stuffs it into temp box 0. And before that temp box gets overwritten with something else, scales it to the desired size and set the box. In this case, I have stuffed the wide content into the macro \widecontent so that I could use it more than once; however, you could choose to place your actual extended code between the braces that follows the \hbox.
[EDIT: After Will Adams pointed out in comments several ways to make the box fit exactly to the margins, I revised my solution to provide yet another way to do that, with the macro \fullwidth, employing the fp package, and an approach originally noted by egreg and employed by percusse in Dividing dimensions to get a count ]
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{fp}
\newsavebox{\tempbox}
\newcount\mywidthcount
\newcount\textwidthcount
\newcommand\fullwidth[1]{%
\sbox{\tempbox}{#1}%
\mywidthcount=\wd\tempbox\relax%
\textwidthcount=\textwidth\relax%
\FPdiv\thescaleratio{\the\textwidthcount}{\the\mywidthcount}%
\scalebox{\thescaleratio}{\usebox{\tempbox}}
}
\parskip 1ex
\parindent 0ex
\begin{document}
This is the margin width:\\
\rule{\textwidth}{.5ex}
\def\widestuff{%
\begin{tabular}{|c|c|c|c|}
\hline
this will hopefully & be long enough so that &
it goes off the right margin& of the page\\
\hline
\end{tabular}
}
Here is unaltered wide stuff:\\
\widestuff
Here is scaled to 0.8 original size:
\setbox0=\hbox{\widestuff}
{\par\centering\scalebox{.8}{\box0}\par}
Here is scaled to fit the text width exactly:\\
\fullwidth{\widestuff}
\fullwidth{xxx}
\end{document}

adjustbox package is suggested instead.
– WillAdams
Aug 29 '13 at 14:14