如何在两列内绘制没有缩进的网格?

如何在两列内绘制没有缩进的网格?

我正在使用以下解决方案如何在 tikz 中绘制类似目录树格式的箭头?内部\documentclass[5p,times]{elsarticle}格式。

代码:

\documentclass[5p,times]{elsarticle}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
    chains,
    positioning,
    shapes.geometric
}
\begin{document}
\begin{frontmatter}
    \title{Title}
    \author{So Nia}
    \address{Department, University}
    \ead{[email protected]}
    \begin{abstract}
        \lipsum*[2]
    \end{abstract}
\end{frontmatter}
\section{Example}
\begin{tikzpicture}[
        node distance = 4mm and 8mm,
        arr/.style = {-Stealth, semithick},
        C/.style = {circle, draw, font=\footnotesize},
        N/.style = {draw, very thick,
                font=\small, align=left,
                inner sep=5pt}
    ]
    \draw[help lines] (0,0) grid (8,5);
    %
    \node (n1) [N] at (3,4) {\$ gcc -g -c \\
        \hphantom{\$ } -fPIC - Wall \\
        \hphantom{\$ } mod1.c mod2.c mod3.c};
    \node[C, below left = 0 and 2mm of n1.north west] {1};
    \node (n2) [N, below right=of n1.south]     {mod1.o code};
    \node (n3) [N, below=of n2]     {mod2.o code};
    \node (n4) [N, below=of n3]     {mod3.o code};
    %
    \draw[arr] (n1) |- (n2);
    \draw[arr] (n1 |- n2) |- (n3);
    \draw[arr] (n1 |- n3) |- (n4);
\end{tikzpicture}
\lipsum[1-1]
\end{document}

输出:

在此处输入图片描述

网格从 aa 段落开始的位置开始。是否可以强制网格开始而不缩进(我只想将其移到下方1.)?

1. Example
------
|  |  |
|  |  |
------
    Lorem ...
Ut purus ....

答案1

tikzpicture一个方框;在这里,它在 之后开始一个新段落\section{Example}。如果将 放在\noindent之前\begin{tikzpicture},则段落将不带任何缩进。

\documentclass[5p,times]{elsarticle}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{
    arrows.meta,
    chains,
    positioning,
    shapes.geometric
}

\begin{document}
\begin{frontmatter}
    \title{Title}
    \author{So Nia}
    \address{Department, University}
    \ead{[email protected]}
    \begin{abstract}
        \lipsum*[2]
    \end{abstract}
\end{frontmatter}
\section{Example}

\noindent   % <--------------- this
\begin{tikzpicture}[
        node distance = 4mm and 8mm,
        arr/.style = {-Stealth, semithick},
        C/.style = {circle, draw, font=\footnotesize},
        N/.style = {draw, very thick,
                font=\small, align=left,
                inner sep=5pt}
    ]
    \draw[help lines] (0,0) grid (8,5);
    %
    \node (n1) [N] at (3,4) {\$ gcc -g -c \\
        \hphantom{\$ } -fPIC - Wall \\
        \hphantom{\$ } mod1.c mod2.c mod3.c};
    \node[C, below left = 0 and 2mm of n1.north west] {1};
    \node (n2) [N, below right=of n1.south]     {mod1.o code};
    \node (n3) [N, below=of n2]     {mod2.o code};
    \node (n4) [N, below=of n3]     {mod3.o code};
    %
    \draw[arr] (n1) |- (n2);
    \draw[arr] (n1 |- n2) |- (n3);
    \draw[arr] (n1 |- n3) |- (n4);
\end{tikzpicture}

\lipsum[1-1]
\end{document}

在此处输入图片描述

相关内容