我正在尝试制作一个图表,所以最终得到了类似这种菱形的形状
\documentclass[a4paper,11pt]{book}%
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{cd}
\begin{document}
\begin{tikzcd}
& \mbox{something very long} \arrow[dr] \arrow[dl]&\\
\mbox{something long} \arrow[dr] && \mbox{something long} \arrow[dl]\\
& \mbox{something very long}&
\end{tikzcd}
\end{document}
但是(正如 tikzcd 最初的设计目的一样)中间行的中间列留下了一大片空白。在我的文档中,这导致溢出侧边距的问题。长期以来,我处理的图表都放在一行中,因此宽度超过页面的三分之一,但高度只有一行(如此宽但很短,以至于空白处感觉不必要地宽,而高度仍然很短)
我想知道是否有办法摆脱 tikz 中这个幽灵中间列,例如,如果我可以有一个 2 列系统,将顶行和底行合并为一列
答案1
不需要直接使用 TikZ。
如果您希望列间距更近,只需设置适当的列分隔符 ( column sep
),也可以为负数。
另外,没有必要使用\mbox
,既然你装了amsmath
,你就可以使用\text
。
\documentclass[a4paper,11pt]{book}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{cd}
\begin{document}
\[
\begin{tikzcd}[column sep=-1.5cm]
& \text{something very long} \arrow[dr] \arrow[dl]&\\
\text{something long} \arrow[dr] && \text{something long} \arrow[dl]\\
& \text{something very long}&
\end{tikzcd}
\]
\end{document}
答案2
与@CarLaTeX 的答案类似,但使用column sep={2cm,between origins}
而不是column sep=-1.5cm
。这样,单元格之间的间距由其中心设置。然后,具有不同长度单元格的图表将具有相同形状的箭头,并且即使单元格内容不对称,箭头也将保持对称。
\documentclass[a4paper,11pt]{book}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}[column sep={2cm,between origins}]
& \textup{something very long} \arrow[dr] \arrow[dl]&\\
\textup{something} \arrow[dr] && \textup{something long} \arrow[dl]\\
& \textup{something very long}&
\end{tikzcd}
\hspace{2cm}
\begin{tikzcd}[column sep={2cm,between origins}]
& \textup{something very long} \arrow[dr] \arrow[dl]&\\
\textup{something very long} \arrow[dr] && \textup{something long} \arrow[dl]\\
& \textup{something very long}&
\end{tikzcd}
\]
\end{document}
答案3
不确定它是否更像“钻石”,但我的试用结果是cd
:
TikZ
正如评论中提到的那样,您似乎更喜欢简单的方法。
\documentclass[a4paper,11pt]{book}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{cd}
\begin{document}
\begin{tikzcd}[column sep=small]
& \mbox{something very long} \arrow[ddr] \arrow[ddl] & \\
\\
\mbox{something long} \arrow[dr] & & \mbox{something long} \arrow[dl] \\
& \mbox{something very long} &
\end{tikzcd}
\begin{tikzpicture}[node distance=2cm]
% Nodes
\node (top) at (0,0) {something very long};
\node (left) at (-2,-1.5) {something long};
\node (right) at (2,-1.5) {something long};
\node (bottom) at (0,-3) {something very long};
% Arrows
\draw[->] (top) -- (left);
\draw[->] (top) -- (right);
\draw[->] (left) -- (bottom);
\draw[->] (right) -- (bottom);
\end{tikzpicture}
\end{document}