如何減少 Tikz 流程圖中行之間的垂直距離?

如何減少 Tikz 流程圖中行之間的垂直距離?

我是 Latex 和 Tikz 的新手,非常感謝您的幫助。這是我的程式碼,我想刪除圖中紅色箭頭所示的空格。

這是我的程式碼:

\documentclass[margin=3mm]{standalone} \usepackage{tikz} \begin{document} 
\begin{tikzpicture}[node distance=2cm, process/.style = {draw, rounded corners, minimum width=6cm, minimum height=1cm, text width= 6cm, align=center}] 
\node (pro1) [process] {Create expensive vectors from expensive paths}; 
\node (pro2) [process, below of=pro1] {Process 1}; 
% Drawing lines 
\draw [->] (pro1) -- (pro2); 
\end{tikzpicture} 
\end{document}

在此輸入影像描述

答案1

我猜您的文件與下面的 MWE(最小工作範例)具有類似的結構。在第一個範例中,它重現了您的問題,在第二個範例中包含了解決方法:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{setspace}  % <---
\setstretch{1.5}       % <---

\usepackage{lipsum}

\begin{document}
MWE, which reproduce your problem:
    \begin{figure}[ht]
\begin{tikzpicture}[node distance=1cm,
process/.style = {draw, rounded corners,
                  minimum width=6cm, minimum height=1cm, text width= 6cm, align=center}
                  ]
\node (pro1) [process] {Create expensive vectors from expensive paths};
\node (pro2) [process, below=of pro1] {Process 1};
\draw [->] (pro1) -- (pro2);
\end{tikzpicture}
    \end{figure}

MWE with cure for your problem:
    \begin{figure}[ht]
    \setstretch{1}          % <===
\begin{tikzpicture}[node distance=1cm,
process/.style = {draw, rounded corners, 
                  minimum height=1cm, text width= 6cm, align=center}
                  ]
\node (pro1) [process] {Create expensive vectors from expensive paths};
\node (pro2) [process, below=of pro1] {Process 1};
\draw [->] (pro1) -- (pro2);
\end{tikzpicture}
    \end{figure}
\end{document}

在此輸入影像描述

\onehalfspacing透過比較您的程式碼片段和上面的MWE,您可以輕鬆地發現n個節點內容的放置是錯誤的。它必須是之前的,tikzpicture如第二個範例所示。

在第一個範例中,我將其從節點中刪除,因為它會導致編譯時出錯。

要獲得流程圖的更多協助,您應該以 MWE 的形式提供完整的流程圖程式碼。從提供的程式碼片段可以得出結論,您使用已棄用的命令進行樣式設定和奇怪的定位方式:更好的是上面 MWE 中使用的方法(positioning其語法中帶有庫)。

相關內容