![我的 tikz-cd 图表不适合文本区域](https://linux22.com/image/396153/%E6%88%91%E7%9A%84%20tikz-cd%20%E5%9B%BE%E8%A1%A8%E4%B8%8D%E9%80%82%E5%90%88%E6%96%87%E6%9C%AC%E5%8C%BA%E5%9F%9F.png)
如何使我的图表适合文本区域?这是一个示例图表 - 我还有其他图表,它们也有类似的问题,所以我希望有一个通用的解决方案。
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{shapes}
\usepackage[dvipsnames]{xcolor}
\begin{document}
\begin{figure}
\centering
\begin{tikzcd}[
cells={nodes={draw=black, ellipse, anchor=center, minimum height=\nodeheight}}]
new\ Channel(low) \arrow[Rightarrow, dd, PineGreen, bend right=50] &
new\ Channel(low) \arrow[Rightarrow, dd, PineGreen] &
new\ Channel(low) \arrow[Rightarrow, dd, PineGreen, bend right=50]\\
|[fill=darkgray,text=yellow]|low \arrow[rightarrow, d, violet] &
& |[fill=darkgray,text=yellow]|low \arrow[rightarrow, d, violet]\\
inLow1 \arrow[Rightarrow, d, PineGreen] &
outLow \arrow[rightarrow, d, violet] &
inLow2 \arrow[Rightarrow, d, PineGreen]\\
read(inLow1) \arrow[Rightarrow, d, PineGreen] &
|[fill=darkgray,text=yellow]|low &
read(inLow2) \arrow[Rightarrow, d, PineGreen]\\
a.f \arrow[Leftrightarrow, r, WildStrawberry] &
c.f \arrow[rightarrow, u, violet] &
b.f \arrow[Leftrightarrow, l, WildStrawberry]\\
a \arrow[Rightarrow, r, PineGreen] &
c \arrow[violet]{u}[description]{\text{inference rule}} &
b \arrow[Rightarrow, l, PineGreen]\\
new\ Foo \arrow[Rightarrow, u, PineGreen] &
read(inHigh) \arrow[rightarrow, u, violet] &
new\ Foo \arrow[Rightarrow, u, PineGreen]\\
& inHigh \arrow[Rightarrow, u, PineGreen] &\\
& |[fill=darkgray,text=yellow]|high \arrow[rightarrow, u, violet] &\\
& new\ Channel(high) \arrow[Rightarrow, uu, PineGreen, bend right=50]
\end{tikzcd}
\end{figure}
\end{document}
答案1
没有“通用的解决方案”:如果你的行李箱很大,你可以把一头大象塞进去;如果你的行李箱很小,你就塞不进去,你需要缩小大象的体积。
此版本适合标准文本宽度article
。
我添加了一个定义\nodeheight
,它似乎并不影响宽度。
\documentclass{article}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz-cd}
\usetikzlibrary{shapes}
\usepackage{showframe} % just to see the margins
\def\nodeheight{24pt}
\begin{document}
\begin{figure}
\centering\footnotesize
\begin{tikzcd}[column sep=small,
cells={nodes={draw=black, ellipse, anchor=center, minimum height=\nodeheight}}]
\text{new Channel(low)} \arrow[Rightarrow, dd, PineGreen, bend right=50] &
\text{new Channel(low)} \arrow[Rightarrow, dd, PineGreen] &
\text{new Channel(low)} \arrow[Rightarrow, dd, PineGreen, bend right=50]\\
|[fill=darkgray,text=yellow]|\text{low} \arrow[rightarrow, d, violet] &
& |[fill=darkgray,text=yellow]|\text{low} \arrow[rightarrow, d, violet]\\
\text{inLow1} \arrow[Rightarrow, d, PineGreen] &
\text{outLow} \arrow[rightarrow, d, violet] &
\text{inLow2} \arrow[Rightarrow, d, PineGreen]\\
\text{read(inLow1)} \arrow[Rightarrow, d, PineGreen] &
|[fill=darkgray,text=yellow]|\text{low} &
\text{read(inLow2)} \arrow[Rightarrow, d, PineGreen]\\
\text{a.f} \arrow[Leftrightarrow, r, WildStrawberry] &
\text{c.f} \arrow[rightarrow, u, violet] &
\text{b.f} \arrow[Leftrightarrow, l, WildStrawberry]\\
\text{a} \arrow[Rightarrow, r, PineGreen] &
\text{c} \arrow[violet]{u}[description]{\text{inference rule}} &
\text{b} \arrow[Rightarrow, l, PineGreen]\\
\text{new Foo} \arrow[Rightarrow, u, PineGreen] &
\text{read(inHigh)} \arrow[rightarrow, u, violet] &
\text{new\ Foo} \arrow[Rightarrow, u, PineGreen]\\
& \text{inHigh} \arrow[Rightarrow, u, PineGreen] &\\
& |[fill=darkgray,text=yellow]|\text{high} \arrow[rightarrow, u, violet] &\\
& \text{new Channel(high)} \arrow[Rightarrow, uu, PineGreen, bend right=50]
\end{tikzcd}
\end{figure}
\end{document}
该showframe
包仅用于显示图表适合。
您应该使用\text
标签,这已经节省了很多空间。