我创建了下图(我只是在它周围添加了一个框):
\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\fbox{
\begin{tikzcd}
\ar[loop left, in=150, out=-150, distance=2cm,"-1"']
\ar[loop left, in=148, out=-148, distance=3cm, "-2"']
\ar[loop left, in=146, out=-146, distance=3.7cm, font=\tiny, phantom,
"\dots"']
\ar[loop left, in=146, out=-146, distance=5cm, "-k"']
\ar[loop left, in=146, out=-146, distance=6cm, phantom, "\dots"'] m
\ar[loop above, in=60, out=120, distance=1cm,"\id_m"]
\ar[loop right, in=30, out=-30,distance=2cm,"+1"]
\ar[loop right, in=32, out=-32, distance=3cm, "+2"]
\ar[loop left, in=34, out=-34, distance=3.7cm, font=\tiny, phantom,
"\dots"]
\ar[loop right, in=34, out=-34, distance=5cm, "+k"]
\ar[loop left, in=34, out=-34, distance=6cm, font=\tiny, phantom,
"\dots"]
\end{tikzcd}}
\end{document}
该图完全符合我的要求,但前后空间太大。如何纠正?添加
\vspace*{xxx}
显然是可能的,但我发现这太不合理了。有什么建议吗?
答案1
你可以做
\begin{tikzcd}[
execute at begin picture={
\useasboundingbox (-4.5,-1.5) rectangle (4.5,1.5);
}
]
不过,确实需要一些反复试验才能找到合适的坐标。
\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\fbox{
\begin{tikzcd}[
execute at begin picture={
\useasboundingbox (-4.5,-1.5) rectangle (4.5,1.5);
}
]
\ar[loop left, in=150, out=-150, distance=2cm,"-1"']
\ar[loop left, in=148, out=-148, distance=3cm, "-2"']
\ar[loop left, in=146, out=-146, distance=3.7cm, font=\tiny, phantom,
"\dots"']
\ar[loop left, in=146, out=-146, distance=5cm, "-k"']
\ar[loop left, in=146, out=-146, distance=6cm, phantom, "\dots"'name=dot1] m
\ar[loop above, in=60, out=120, distance=1cm,"id_m"]
\ar[loop right, in=30, out=-30,distance=2cm,"+1"]
\ar[loop right, in=32, out=-32, distance=3cm, "+2"]
\ar[loop left, in=34, out=-34, distance=3.7cm, font=\tiny, phantom,
"\dots"]
\ar[loop right, in=34, out=-34, distance=5cm, "+k"]
\ar[loop left, in=34, out=-34, distance=6cm, font=\tiny, phantom,
"\dots"name=dot2]
\end{tikzcd}}
\end{document}
答案2
在弄乱了你的图表后,我实现了这个:
(盲文只是为了提供背景)。
问题似乎是图表的高度和深度都太大,出于某种原因我不明白。
编辑:
问题在于,正如@TorbjørnT. 所说,因为\fbox
在框架中包含了曲线的控制点。所以以下解决方案仅在图表对称的情况下才有效!如果图表不对称,那么不幸的是,这个解决方案将不起作用......
为了解决这个问题,我使用了\putbox
几周前做的一个宏的修改版本。这个宏将只考虑图表的高度而不考虑其深度,在图表周围画一个框。
它并不漂亮,但我认为它有效:
\documentclass{article}
\usepackage{tikz}
\usepackage{blindtext}
\usetikzlibrary{cd}
\newcommand{\putbox}[2][]{%
\ifdefined\xboxh%
\relax%
\else%
\newlength{\xboxh}%
\newlength{\xboxw}%
\newlength{\xboxd}%
\fi%
\settoheight{\xboxh}{#2}%
\settowidth{\xboxw}{#2}%%
\settodepth{\xboxd}{#2}%
\frame{\phantom{\rule{\xboxw}{\dimexpr\xboxh}}}%
\if\relax\detokenize{#1}\relax%
\relax%
\else%
\setlength{\xboxh}{0.5\xboxw}%
\settowidth{\xboxw}{#1}%
\setlength{\xboxw}{0.5\xboxw}%
\hspace{\dimexpr-\xboxw-\xboxh}%
\vskip-\xboxh%
#1%
\hspace{\dimexpr \xboxh-\xboxw}%
\vskip\xboxd%
\vskip-\xboxh%
\fi\relax%
}
\newcommand{\mycd}{%
\begin{tikzcd}%
\ar[loop left, in=150, out=-150, distance=2cm,"-1"']%
\ar[loop left, in=148, out=-148, distance=3cm, "-2"']%
\ar[loop left, in=146, out=-146, distance=3.7cm, font=\tiny, phantom,%
"\dots"']%
\ar[loop left, in=146, out=-146, distance=5cm, "-k"']%
\ar[loop left, in=146, out=-146, distance=6cm, phantom, "\dots"'] m %
\ar[loop above, in=60, out=120, distance=1cm,"Id_m"]%
\ar[loop right, in=30, out=-30,distance=2cm,"+1"]%
\ar[loop right, in=32, out=-32, distance=3cm, "+2"]%
\ar[loop left, in=34, out=-34, distance=3.7cm, font=\tiny, phantom,%
"\dots"]%
\ar[loop right, in=34, out=-34, distance=5cm, "+k"]%
\ar[loop left, in=34, out=-34, distance=6cm, font=\tiny, phantom,%
"\dots"]%
\end{tikzcd}%
}
\begin{document}
\blindtext
\putbox[\mycd]{\mycd}
\blindtext
\end{document}