节点对齐:下方

节点对齐:下方

我正在尝试对齐结构 %first、%second 和 %third。我尝试了一些对齐选项,使用以下对齐但他们并没有按照我的期望去做。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{blindtext}
\usetikzlibrary{positioning}

\begin{document}




\begin{tikzpicture}
    % First
    \node[fill opacity=0.1,circle,label=left:n1-label,fill=black] at (0,0) (n1) {};
    \node[right=0cm of n1,draw,fill=none, text width=\linewidth-2.4cm] (n2) {
        title2
    };
    \node[below=0.5cm of n2,draw,text width=\linewidth-2.4cm] (n3){
        Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah 
        \blinditemize
    };

    % Second
    \node[below=1cm of n3,fill opacity=0.1,circle,label=left:n4-label,fill=black] at (0,0) (n4) {};
    \node[right=0cm of n4,draw,fill=none, text width=\linewidth-2.4cm] (n5) {
        title2
    };
    \node[below=0.5cm of n5,draw,text width=\linewidth-2.4cm] (n6){
        Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah 
        \blinditemize
    };

    % Third
    \node[below=1cm of n6,fill opacity=0.1,circle,label=left:n7-label,fill=black] at (0,0) (n7) {};
    \node[right=0cm of n7,draw,fill=none, text width=\linewidth-2.4cm] (n8) {
        title3
    };
    \node[below=0.5cm of n8,draw,text width=\linewidth-2.4cm] (n9){
        Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah 
        \blinditemize
    };


\end{tikzpicture}
\end{document}

b) 我还想让 n2、n3、n5、n6 跨越到刚好到达右边距。

更新:代码已根据一些建议进行了更新,b)已修复,感谢@marmot

答案1

第一个答案:一些评论:

  1. 定位仅在一个 s 内有效tikzpicture,而不能跨单独的tikzpictures 进行定位,除非您使用overlay。但是,在这种情况下,我不会那样做。
  2. 您的语法right of=n1已被弃用,甚至在 pgfmanual 中都不再提及。加载positioning库并执行类似操作将为您带来巨大好处right=5mm of n1
  3. 如果不指定文本的宽度,节点将变得任意宽。为了避免这种情况,请设置适当的text width

建议代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{blindtext}
\begin{document}

\noindent
\begin{tikzpicture}[buffl/.style={fill opacity=0.1,circle,fill=black}]
\node[buffl,label=left:foo] at (0,0) (n1) {};
\node[draw,fill=none, right=1cm of n1, text width=\linewidth-3.4cm] (n5) {
    title5
};
\node[draw,below=1cm of n5, text width=\linewidth-3.4cm] (n6){
    \blindtext
};
\node[draw,below=1cm of n6, align=center,text width=\linewidth-3.4cm] (n3) {
    \blindtext
};
\node[buffl,label=left:n4-label,left=1cm of n3]  (n4) {};

\draw[fill opacity=0.1] ([yshift=-0.25cm]n1.south) -- ([yshift=0.25cm]n4.north);

\end{tikzpicture}

\end{document}

enter image description here

对你更新的回复:鉴于您更新的问题,我实际上想知道您是否最好使用表格,然后只需通过覆盖在它们之间添加项目符号和线条。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage{tabularx}
\usetikzlibrary{positioning}

\begin{document}
\tikzset{every picture/.append style={remember picture},
fluffy/.style={fill opacity=0.1,circle,fill,inner sep=3pt,outer sep=1mm}}

\blindtext

\noindent\begin{tabularx}{\linewidth}{@{} l @{~} |X| @{}}
\cline{2-2}
\begin{tikzpicture}[baseline=(l1.base)]
 \node[fluffy,label={[name=l1]left:n1-label}] at (0,0) (n1) {};
\end{tikzpicture}   
& title2\\
\cline{2-2}
\multicolumn{1}{c}{~}& \multicolumn{1}{c}{~}\\
\cline{2-2}
&
 Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah 
 \blinditemize
\\
\cline{2-2}
\multicolumn{1}{c}{~}& \multicolumn{1}{c}{~}\\
\cline{2-2}
\begin{tikzpicture}[baseline=(l2.base)]
 \node[fluffy,label={[name=l2]left:n2-label}] at (0,0) (n2) {};
\end{tikzpicture}   
& title2\\
\cline{2-2}
\multicolumn{1}{c}{~}& \multicolumn{1}{c}{~}\\
\cline{2-2}
&
 Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah Blah blah 
 \blinditemize 
\\
\cline{2-2}
\end{tabularx}
\begin{tikzpicture}[overlay]
\draw (n1) -- (n2);
\end{tikzpicture}
\end{document}

enter image description here

答案2

我可以建议另一种方法吗?我建议使用tcolorboxes,它们很容易对齐,因为使用整个文本宽度,可以记住在它们之间画线,可以使用覆盖选项添加标签,...

以下第一个近似定义了两种类型的框,mytitlemytextmytitle框使用强制参数,即label所附圆的。此标签也将是节点的名称。\mytext框包含较长的文本,它们可以在页面之间拆分。

两种节点都可以使用可选参数,可以改变颜色、前一个(before skip)或后一个(after skip)框之间的距离,...

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\usetikzlibrary{positioning}

\tcbset{
    common/.style={%
        enhanced, sharp corners,
        colback=white, colframe=black,
        notitle, left skip=2.4cm, size = small,
        }
    }

\newtcolorbox{mytitle}[2][]{
    common,
    after skip=5mm, remember,
    overlay={
        \node[fill opacity=.1, fill=black, circle,
            label=left:#2, left=1mm of frame.west] (#2) {};
    },
    #1
}

\newtcolorbox{mytext}[1][]{
    common, breakable,
    #1
}

\begin{document}

\blindtext
\begin{mytitle}{n1-label}
title 2
\end{mytitle}
\begin{mytext}
\blinditemize
\end{mytext}

\begin{mytitle}[before skip=1cm, after skip=2mm, colframe=blue]{n2-label}
title 2
\end{mytitle}
\begin{mytext}
\blinditemize
\end{mytext}

\begin{tikzpicture}[remember picture, overlay]
\draw[shorten >=2mm, shorten <=2mm] (n2-label)--(n1-label);
\end{tikzpicture}
\end{document}

enter image description here

相关内容