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}
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.
Right after the coordinates for the boxplot
, add the code for one of the nodes found in the example in the manual. I just changed left
to above
/below
, and reduced the inner sep
to get the number closer to the line.
\documentclass[12pt,tikz,border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{pgfplots.statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = .5\textwidth,
height = 12cm,
axis x line*=bottom,
axis y line=left,
enlarge y limits,
ymajorgrids,
major x tick style = transparent,
ylabel = {Time},
ymin=8.15,
ymax=40,
xmin=0,
xmax=3,
xticklabels={,,},
xtick={1,...,3},
boxplot/draw direction=y,
]
\addplot+[boxplot prepared={
lower whisker=9.06, lower quartile=9.29,
median=12.10,
upper quartile=13.125, upper whisker=14.05,
box extend=0.4}, color=blue
]
coordinates {}
node[above,inner sep=1pt,font=\tiny] at
(boxplot box cs: \boxplotvalue{median},0.5)
{\pgfmathprintnumber{\boxplotvalue{median}}};;
\addplot+[boxplot prepared={
lower whisker=19.22, lower quartile=20.255,
median=21.58,
upper quartile=30.15, upper whisker=30.15,
box extend=0.4}, color=red]
coordinates {(0, 37.05)}
node[above,inner sep=1pt,font=\tiny] at
(boxplot box cs: \boxplotvalue{median},0.5)
{\pgfmathprintnumber{\boxplotvalue{median}}};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
The
witharrows
package can do something like this.There is a semi-automatic way to get line breaks in the text as well, you will need to specify a text width, then the label will be broken to fit into the horizontal space.
This solution is semi-automatic since you have to find a good value for
text-width
yourself meaning that for occasional use it is probably not faster than giving manual breaks with\\
.As soon as the text occupies multiple lines you run the risk of running into the labels above or below.
Version 1.9 of
witharrows
define a replacement environments foralign
in which labels can be wrapped automatically. Thanks to F. Pantigny for the hint in the comments.