4

I want to adjust the width of an displaymath environment whose contents (a tikzcd diagram rather than an actual equation) are too wide to fit in the margins. The obvious thing to do is to use the adjustwidth environment, but this doesn't work as well as I would like: the vertical spacing of the result is sometimes quite ugly. (It seems to be some kind of conflict with mathtools, see below.)

It seems to me that the problem is in the implementation of adjustwidth using list. Perhaps there is an alternative / more direct way of adjusting the margins of part of a page that works better with equation?

enter image description here

\documentclass[12pt,a4paper]{article}

\usepackage{mathtools}
\usepackage{changepage}
\usepackage{tikz-cd}

\newcommand{\sample}{Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate.}

\begin{document}
\sample
\begin{adjustwidth}{-0.5in}{-0.5in}
\[
\begin{tikzcd}
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \\
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet
\end{tikzcd}
\]
\end{adjustwidth}
\sample
\end{document}

enter image description here

6
  • 1
    Could you make a real world example, as this isn't really meaningful? And, please, don't use the minimal class.
    – egreg
    Aug 29, 2014 at 11:24
  • If this is for a printed article/book/thesis, I'd advise against scaling the font. Instead, I'd try to stretch/shrink the arrows based on the width of the page.
    – user10274
    Aug 29, 2014 at 11:41
  • @egreg I replaced it with a real world example. Note the asymmetrical vertical spacing for the second diagram compared to the third diagram; adding \vskip -1em after \begin{adjustwidth} makes things look better.
    – Zhen Lin
    Aug 29, 2014 at 12:58
  • 2
    is it possible that you have left a blank line before the second display? that will disrupt the spacing above a display, but to be certain, we need to see the actual code for the problem area, presented as a compilable example. another trick you might try is to insert on both sides of the diagram a negative horizontal space (the same width on both sides) to trick tex into thinking the display is narrower. Aug 29, 2014 at 13:42
  • I like your idea with \hspace! It works well enough for my use case. As for blank lines, I have not left any, but perhaps mathtools has...
    – Zhen Lin
    Aug 29, 2014 at 14:38

1 Answer 1

4

The first thing to try is, of course, reducing the arrow lengths. If all else fails, use \mathclap that, however, requires ampersand replacement; or enclose the diagram in an lrbox.

I'll show all three possibilities.

\documentclass[12pt,a4paper]{article}

\usepackage{mathtools}
\usepackage{tikz-cd}

\newsavebox{\wideeqbox}

\newcommand{\sample}{Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor 
in reprehenderit in voluptate.}

\begin{document}
\sample
\[
\mathclap{
\begin{tikzcd}[ampersand replacement=\&]
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \rar \&
\bullet \dar \\
\bullet \rar \&
\bullet \rar \&
\bullet \rar \&
\bullet \rar \&
\bullet \rar \&
\bullet \rar \&
\bullet \rar \&
\bullet \rar \&
\bullet \rar \&
\bullet
\end{tikzcd}
}
\]
\sample
\[
\begin{lrbox}{\wideeqbox}
$\begin{tikzcd}
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \\
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet
\end{tikzcd}$
\end{lrbox}
\makebox[0pt]{\usebox{\wideeqbox}}
\]
\sample
\[
\begin{tikzcd}[column sep=2em,row sep=1.5em]
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \rar &
\bullet \dar \\
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet \rar &
\bullet
\end{tikzcd}
\]
\sample

\end{document}

enter image description here

The lrbox solution can be packaged into an environment:

\newsavebox{\wideeqbox}
\newenvironment{wideeq}
  {\begin{displaymath}\begin{lrbox}{\wideeqbox}$\displaystyle}
  {$\end{lrbox}\makebox[0pt]{\usebox{\wideeqbox}}\end{displaymath}}

Then

text
\begin{wideeq}
\begin{tikzcd}
...
\end{tikzcd}
\end{wideeq}
text

will do. Any math mode material can be used.

4
  • I think your solution with lrbox seems most reasonable. Do you think it could be packaged into a new environment?
    – Zhen Lin
    Aug 29, 2014 at 18:09
  • @ZhenLin Sure, I added it.
    – egreg
    Aug 29, 2014 at 19:21
  • I think you missed a \end{lrbox} in your code, but otherwise it works. Thanks!
    – Zhen Lin
    Aug 29, 2014 at 19:37
  • Yes, it was missing. Fixed.
    – egreg
    Aug 29, 2014 at 19:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .